【解决问题】OpenCV(3.4.1) Error: Assertion failed..opencv/modules/highguic/window.cpp.. cv::Exception

本博客运行环境为Ubuntu18.04 KDevelop。

问题描述:
OpenCV(3.4.1) Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/hadoop/opencv-3.4.1/modules/highguic/window.cpp, line 364
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(3.4.1) /home/hadoop/opencv-3.4.1/modules/highguic/window.cpp:364: error: (-215) size.width>0 && size.height>0 in function imshow

解决方法

把对应的读取图片的位置,改为使用绝对路径读取。

例如,我原先的代码为

first_file = "/home/hadoop/projects/slamTest/dataset/kitti/000000.png";
cv::Mat first_image = cv::imread(first_file, 0);

改为

cv::Mat first_image = cv::imread("/home/hadoop/projects/slamTest/dataset/kitti/000000.png");

如果是循环多张图片,就改为

std::string pattern_jpg = "/home/hadoop/projects/slamTest/dataset/kitti/*.png";
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章