Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV imwrite 2.2 causes exception with message "OpenCV Error: Unspecified error (could not find a writer for the specified extension)" on Windows 7

I'm porting an OpenCV 2.2 app from Unix (that works) onto Windows 7 64-bit and I receive the following exception when cv::imwrite is called

"OpenCV Error: Unspecified error (could not find a writer for the specified extension) in unknown function, file highgui\src\loadsave.cpp"

The original unix app works fine on my Mac and Linux boxes.

Does anyone know what library or compiler config I could be missing that makes this work on Windows?

UPDATE:

I did the following things to get OpenCV running:

  • Downloaded the binaries for v2.2 from the OpenCV site for windows. I'm using 2.2 because the original app uses it and I don't want to complicate my build at this stage.
  • I am trying to imwrite to a .png file. I looked at the OpenCV code and noticed the necessity for external libs for Encoders such as Pngs or jpegs, so I tried writing to .ppm, .bmp which seems not to require deps, but I get the identical error.
  • An example of my usage is cv::imwrite("out.png", cv_scaled); where cv_scaled is of type cv::Mat with format CV_32FC1
  • Please remember the identical code works fine in unix

The fact .bmp or .ppm doesn't work this raises more questions:

  • Why don't these very simple formats work?
  • Is there a way to see a list of installed Encoders programmatically?

Thanks again for your kind assistance in helping me debug this problem.

like image 237
CVertex Avatar asked Aug 03 '11 07:08

CVertex


1 Answers

Your current installation of OpenCV doesn't support the file format you are trying to create on disk.

Check if the extension of the file is right. If it is, you'll have to recompile OpenCV and add support to this format and possibly install the libraries you are missing.

That's all that can be said without more information.

EDIT:

As I have also failed building an application that uses the C++ interface of OpenCV (v2.3 on VS2005) I ended up using the following workaround: convert the C++ types to the C types when necessary.

To convert from IplImage* to cv::Mat is pretty straight forward:

IplImage* ipl_img = cvLoadImage("test.jpg", CV_LOAD_IMAGE_UNCHANGED);
Mat mat_img(ipl_img);

imshow("window", mat_img);

The conversion cv::Mat to IplImage* is not so obvious, but it's also simple, and the trick is to use a IplImage instead of a IplImage*:

IplImage ipl_from_mat((IplImage)mat_img);

cvNamedWindow("window", CV_WINDOW_AUTOSIZE);
// and then pass the memory address of the variable when you need it as IplImage*
cvShowImage("window", &ipl_from_mat); 
like image 112
karlphillip Avatar answered Nov 16 '22 00:11

karlphillip