【解決問題】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";
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章