First Program OpenCV 2.4.8 with VS2012 not working

asked 2014-03-25 05:54:46 -0500

Pietro gravatar image

updated 2014-03-25 06:04:56 -0500

berak gravatar image

Hi all,

I'm trying to run my first project with OpenCV 2.4.8 and VS 2012. This is the code:

int _tmain(int argc, _TCHAR* argv[]) {

cv::Mat image = cv::imread("c:\\img.jpg");
//std::cout << cv::imread("C:\\img.jpg") << std::endl; --> this print out []
cv::namedWindow("MyImage");
cv::imshow("MyImage",image);
cv::waitKey(10000);
return 1;

}

And I have this error:

Opencv error assertion failed (size.width 0 && size.height 0) in cv::imshow, file C:\builds\2_4_PackSlave-win32-vc11-shared\opencv\modules\highgui\scr\window.cpp,line 261

In addition, if I run this code, instead the previous code, I have no errors:

int _tmain(int argc, _TCHAR* argv[]) {

IplImage* iplImage = cvLoadImage("c:\\img.jpg");
cv::Mat image(iplImage,false);
cv::namedWindow("MyImage");
cv::imshow("MyImage",image);
cv::waitKey(10000);
return 1;

}

Can you help me please?

edit retag flag offensive close merge delete

Comments

please triple-check the opencv libs you're linking (compiler version, debug/release, 32/64bit) you're not allowed to mix any settings there

berak gravatar imageberak ( 2014-03-25 06:06:31 -0500 )edit

@berak thanks I work at debug mode and 32 bit processor.

Pietro gravatar imagePietro ( 2014-03-25 06:53:14 -0500 )edit
1

I have tested your code and encoutered no error. The error you got means that the program (imread() function in this case) could not read the image file. I do not know why but you should look at the Character Set option of your program and change its value to see if the problem disappears.

tuannhtn gravatar imagetuannhtn ( 2014-03-25 11:15:02 -0500 )edit