Reputation: 9
I have a small OpenCV code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int
main(int argc, char* argv[])
{
cv::Mat mask_img = cv::imread("image.png");
cv::imshow("window",mask_img);
return 0;
}
Yet when running I get the following error:
OpenCV Error: Assertion failed (0 <= _dims && _dims <= CV_MAX_DIM) in setSize, file /home/box/OpenCV-2.4.3/modules/core/src/matrix.cpp, line 88 terminate called after throwing an instance of 'cv::Exception'
what(): /home/box/OpenCV-2.4.3/modules/core/src/matrix.cpp:88: error: (-215) 0 <= _dims && _dims <= CV_MAX_DIM in function setSizeAborted
I'm using OpenCV 2.4.3 on kubuntu linux, compiled from source.
How can I resolve this error?
I solved it myself, just use
g++ bla2.cpp `pkg-config opencv --cflags --libs` -o bla
Do not use your own linking libraries in addition like -lopencv_core etc
Upvotes: 0
Views: 3876
Reputation: 3988
Is your image read properly? Try adding these lines of code after imread
: if (image.empty()){ std::cerr << "Failed to read image" << std::endl; return 0;}
Upvotes: -1