views:

1153

answers:

2

I'm trying to use the new OpenCV 2.0 API in MS Visual C++ 2008 and wrote this simple program:

cv::Mat img1 = cv::imread("image.jpg",1);
cv::namedWindow("My Window", CV_WINDOW_AUTOSIZE);
cv::imshow("My Window", img1);

Visual Studio returnes an unhandled exception and the Console returns:

OpenCV Error: bad flag (parameter or structure field) 
(Unrecognized or unsupported array type) in unknown function, 
file ..\..\..\..\ocv\opencv\src\cxcore\cxarray.cpp, line 2376

The image is not displayed. Furthermore the window "My Window" has a strange caption: "ÌÌÌÌMy Window", which is not dependent on the name.

The "old" C API using commands like cvLoadImage, cvNamedWindow or cvShowImage works without any problem for the same image file. I tried a lot of different stuff without success.

I appreciate any help here.

Konrad

A: 

As I just commented, imread isn't working for me either. A little googling shows other people having the same problem; I guess it's a bug in the library code. For now, here's a hacky workaround:

IplImage* img = cvLoadImage("lena.jpg");
cv::Mat lena(img);
cvReleaseImage(&img);

This way, you can at least use the C++ API for the rest of your stuff.

tzaman
thanks, that's a useful approach - works fine and helps me a lot.
Konrad
Glad to help. Could I bother you to click the up-arrow and checkmark next to this post? :)
tzaman
no worries, I tried. But I'm not allowed yet :)
Konrad
+1  A: 

There's help for this issue.

The solution is, that the usual proposed opencv library files in the linker are not working properly. Instead try to use the debug library files by this:

In Visual C++:

go to Project->Properties (or Alt-F7) Configuration Properties->Linker->Input->Additional Dependencies

replace the usual " cv210.lib cxcore210.lib highgui210.lib" by " cv210d.lib cxcore210d.lib highgui210d.lib" - which are the debugging libraries.

The OpenCv 2.0 API commands should work now.

Konrad
Oh, of course, that would cause problems. Nice catch! Remember to link the non-debug versions for your release mode build, though.
tzaman