cv::imwrite could not find a writer for the specified extension

37

The following command causes an exception.

cv::imwrite("test.jpg", diffImg);

I also tried numerous variations on this, including absolute paths and PNG export. Here's the error:

Exception at 0x75abd36f, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) in opencv_core231!cv::error

C:\slave\WinInstallerMegaPack\src\opencv\modules\highgui\src\loadsave.cpp:276: error: (-2) could not find a writer for the specified extension

According to this related thread my current OpenCV installation doesn't support the image formats I tried. But I merely downloaded the precompiled Windows framework like their site suggested.

How can I get JPG export working?

opencv
asked on Stack Overflow Mar 26, 2012 by Pieter • edited May 23, 2017 by Community

7 Answers

85

I have also faced this issue and I have observed that this issue will come when I use the image without any extension. like abc.jpg but I rename it abc only.

You must use an image name with extension.

answered on Stack Overflow Sep 17, 2015 by NIrav Modi • edited Sep 3, 2020 by NIrav Modi
34

Just mention the format in which you like to save your image like image.jpg, image.jpeg

cv2.imwrite('image.jpg',image)
answered on Stack Overflow Nov 27, 2014 by Shahid Malik • edited Jun 13, 2018 by Pang
8

it sounds as if you were using a different execution environment than the one you are compiling. Can you try the following? Download dependency walker and go to the executable directory and drag and drop the .exe file over dependency walker (http://www.dependencywalker.com/). It will show you which runtime libraries it is using. Now, make sure you are calling the program with the right environment. If you can, use a command line interface to call the program, it will make you feel safer to know where the code is being called from, so you can be sure your copied .dlls are being called.

Kind regards, Daniel

answered on Stack Overflow Apr 3, 2012 by dannyxyz22 • edited Apr 4, 2018 by bit_scientist
0

You need to recompile OpenCV and add support to "jpeg" format. Get the lastest opencv code and run cmake:

svn co http://code.opencv.org/svn/opencv/trunk/opencv myopencvdir.svn/
cd myopencvdir.svn/
mkdir release
cd release/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

And check if libjpeg, libpng, libtiff are supported. If not you need to install them and re-run cmake.

Example of cmake output that shows Media I/O support:

--   Media I/O: 
--     ZLib:                       TRUE
--     JPEG:                       TRUE
--     PNG:                        TRUE
--     TIFF:                       TRUE
--     JPEG 2000:                  TRUE
--     OpenEXR:                    YES
answered on Stack Overflow Mar 26, 2012 by Eric
0

Before trying anything else, be sure you are setting up OpenCV and the VS project according to this answer, and be carefully not to mix OpenCV release libraries with the debug libraries.

There are a couple of things you might try:

  • If you are on Windows 7 64 bits, you might want to follow this or this instructions.

  • I noticed a similar question on javacv wiki and this is another possible solution:

  1. Head over to this page, follow the instructions to setup opencv 2.3.1 till Step 2. (Use 32-bit mode)

  2. Download the latest version of TBB for Windows from here.

  3. Extract the TBB zip file and copy all .dll files inside / bin / ia32 / vc10 and all .dll files in / bin / ia32 / vc10 / irml into your C:\ OpenCV 2.3.1\ build\ x86\ vc10\ bin

Let us know how you did.

answered on Stack Overflow Apr 1, 2012 by karlphillip • edited May 23, 2017 by Community
0

I run into the same runtime error "opencv error unspecified error (could not find a writer for the specified extension)". I used the same solution as Pieter, that is in the project setting-->linker-->Input-->Aditional Dependencies, I specified to use the debug version of the opencv libs for MSVS debug cofiguration, and specify to use the release version of the opencv libs for MSVS release configuration. Then the runtime error is gone.

answered on Stack Overflow Feb 22, 2013 by user2098437
0

Yes,it works for me.
For debug just remove thoes *.lib left *d.lib (Property Pages/Linker/Input/Additional Dependencies), just copy these *d.lib :

answered on Stack Overflow Dec 24, 2014 by chaozding • edited Dec 24, 2014 by Ankur Bhadania

User contributions licensed under CC BY-SA 3.0