I have this nasty problem with opencv 2.4.2. I use VS 2012 to compile this short test programm.
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat sudoku = imread("sudoku.jpg",0);
namedWindow("Lines", CV_WINDOW_AUTOSIZE);
imshow("Lines", sudoku);
}
Imshow is the problem. When I remove it, it runs without any problem. I found a tip here which said to use debug libs instead but it didn't help.
First of all, you have to check if image is loaded correctly. To do this just check if image.data
is NULL
or not.
Secondly, after calling imshow
you have to call waitKey
to show image:
http://opencv.willowgarage.com/documentation/cpp/user_interface.html#cv-waitkey
Here's the whole code:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat sudoku = imread("sudoku.jpg",0);
if (sudoku.data == NULL)
{
cout << "No image found! Check path." << endl;
return 1;//ERROR
}
else
{
namedWindow("Lines", CV_WINDOW_AUTOSIZE);
imshow("Lines", sudoku);
waitKey();//without this image won't be shown
return 0;//OK
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With