Alex Rivera | Logout

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

Asked 2011-08-03T07:56:47.687
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.

Edit
Report

1 Answer

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.

answered 2012-08-17T11:11:53.310

Your Answer