10

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.

CVertex
  • 17,997
  • 28
  • 94
  • 124
  • +1 It's also happening with `imread()` of OpenCV 2.3 on VS 2005 on my WinXP box. – karlphillip Aug 04 '11 at 01:00
  • I had the same problem, and I was using release libraries from OpenCV while building debug. I have changed the libraries to debug libraries and the problem solved. In case anyone did the same sort of mistake as I did. – meakgoz Mar 14 '16 at 08:57

3 Answers3

9

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); 
karlphillip
  • 92,053
  • 36
  • 243
  • 426
4

Try

cvSaveImage("test.jpg", &(IplImage(image)));

instead of

imwrite("test.jpg", image);

This is a known bug in the version you are using.

Can Guney Aksakalli
  • 1,320
  • 1
  • 11
  • 24
0

From the OpenCV 2.2 API:

The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension, see imread for the list of extensions. Only 8-bit (or 16-bit in the case of PNG, JPEG 2000 and TIFF) single-channel or 3-channel (with ‘BGR’ channel order) images can be saved using this function. If the format, depth or channel order is different, use Mat::convertTo , and cvtColor to convert it before saving, or use the universal XML I/O functions to save the image to XML or YAML format.

You might have more luck converting your file to 8 or 16 bits before saving.

However, even with single channel 8 bit files I have had unknown extension errors trying to save jpg or png files but found that bmp works.

Tim MB
  • 4,413
  • 4
  • 38
  • 48