2011-09-16 39 views
3

我想模糊图像,高斯模糊图像,但所有最终发生的事情,当我运行我的代码是图像打开没有模糊。任何人都可以帮我解决这个问题吗?opencv2 bluring图像

#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; 

} 

回答

6

一对夫妇的事情:您正在处理image进入Mat名为result,但随后显示image。另外,在最后两次调用imshow后没有调用waitKey,所以你根本没有看到这些。还有一个小点:从main返回0,表示没有错误,表示信号完成。试试这个:

//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; 
1

cv::imshow("My Image", result);而不是cv::imshow("My Image", image);