Reputation: 73
I wrote a little demo to test whether my OpenCV work or not. My computer contains version 3.4.2 and 3.4.0.
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
int main()
{
cv::Mat image = cv::imread("map.jpg");
cv::imshow("test", image);
cv::waitKey(0);
return EXIT_SUCCESS;
}
CMake file :
cmake_minimum_required(VERSION 3.0.0)
project(opencv_test VERSION 0.1.0)
include(CTest)
enable_testing()
find_package( OpenCV 3.4.2 REQUIRED )
add_executable(opencv_test main.cpp)
target_link_libraries(opencv_test ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Then it throw the exception like this:
OpenCV(3.4.2) /home/robomaster/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
I have tried and checked the following methods:
imread()
and cvLoadImage()
and the ouptut is the same.Upvotes: 0
Views: 259
Reputation: 2347
As per OpenCV docs,
If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL )
which means that after cv::imread
you should check:
cv::Mat image = cv::imread("map.jpg");
if( image.data == nullptr )
return 1; // EXIT_ERROR
Again, as per the docs, possible reasons for failure are:
Possible solutions:
chmod +w map.jpg
Upvotes: 1