I had this line of code in a program that uses OpenCV to write an image buffer to a PNG file:
I was using Visual Studio 2013 to compile and run this file. But, on running I got this error:
opencvmoduleshighguisrcloadsave.cpp:276: error: (-2) could not find a writer for the specified extension
I have found that there are two reasons that this can be caused.
The most logical reason is that OpenCV was compiled with the PNG write feature (or any other format) left out. In this case, you may have to get the OpenCV source code and compile it, making sure you choose to enable
WITH_PNG or similar option enabled in CMake.
Surprisingly, I found that this error can also occur when the OpenCV library you are using has PNG compiled in. However, you may be linking a OpenCV release library (or DLL) with a compilation being done in Debug mode (or vice versa). Ensure that you are using Debug version of the library files in Debug mode and Release files in Release mode. I found that this resolved the error when I got it on Windows! 😊
Tried with: OpenCV 2.4.9, Visual Studio 2013 and Windows 7 x64