对于Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/cc/software/opencv-3.4.1/modules/highgui/src/window.cpp……报错的解决方法
代码如下:
1 #include <iostream> 2 #include <opencv2/highgui/highgui.hpp> 3 #include <opencv2/opencv.hpp> 4 5 using namespace std; 6 7 int main() 8 { 9 cv::Mat srcImage=cv::imread("lena.jpg"); 10 imshow("源图像",srcImage); 11 cv::waitKey(0); 12 return 0; 13 }
cmake以后报错:
OpenCV(3.4.1) Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/cc/software/opencv-3.4.1/modules/highgui/src/window.cpp, line 356
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /home/cc/software/opencv-3.4.1/modules/highgui/src/window.cpp:356: error: (-215) size.width>0 && size.height>0 in function imshow
已放弃 (核心已转储)
解决方法:
把图像的路径替换成绝对路径,问题解决.
例如我的写为:cv::Mat srcImage=cv::imread("/home/cc/test/opencv_project/lena.jpg");