开发者

opencv2 bluring images

开发者 https://www.devze.com 2023-04-05 11:09 出处:网络
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?

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("M开发者_运维百科y 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;   


Do cv::imshow("My Image", result); instead of cv::imshow("My Image", image);.

0

精彩评论

暂无评论...
验证码 换一张
取 消