I'm trying to blur an image , and gaussion blur an image but all that ends up happening when i run my code is the image opens up without bluring. Can anyone help me with this problem?
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main() {
//read the image
cv::Mat image= cv::imread("Space_Nebula.jpg");
cv::Mat result;
// create image window
cv::namedWindow("My Image");
//display image
cv::imshow("My Image", image);
//wait key
cv::waitKey(50000);
//blur image
cv::blur(image,result,cv::Size(5,5));
cv::imshow("My Image", image);
//smooth image
cv::GaussianBlur(image,result,cv::Size(5,5),1.5);
cv::imshow("My Image", image);
return 1;
}
A couple things: You are processing image into the Mat called result but then displaying image. Also, there is no call to waitKey after the last two calls to imshow so you aren't seeing those at all. And a small point: return 0 from main to signal completion with no error. Try this instead:
//read the image
cv::Mat image= cv::imread("../../IMG_0080.JPG");
cv::Mat result;
// create image window
cv::namedWindow("My Image");
//display image
cv::imshow("My Image", image);
//wait key
cv::waitKey(0);
//blur image
cv::blur(image,result,cv::Size(5,5));
cv::imshow("My Image", result);
cv::waitKey(0);
//smooth image
cv::GaussianBlur(image,result,cv::Size(5,5),1.5);
cv::imshow("My Image", result);
cv::waitKey(0);
return 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With