68

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?

Community
  • 1
  • 1
Pieter
  • 31,619
  • 76
  • 167
  • 242
  • Did you download OpenCV-2.3.1-win-superpack.exe? What Windows are you using? 7 or 8? – karlphillip Mar 30 '12 at 12:41
  • I downloaded the v2.3.1 superpack on my Windows 7 computer. I also tried the SVN version (as shown below in the comments) without success. – Pieter Mar 30 '12 at 17:17

7 Answers7

142

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.

NIrav Modi
  • 6,038
  • 8
  • 32
  • 47
51

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

cv2.imwrite('image.jpg',image)
Pang
  • 9,564
  • 146
  • 81
  • 122
Shahid Malik
  • 867
  • 8
  • 15
  • 1
    This answer is also using the Python OpenCV bindings when the question is clearly C++. You need to be more aware of the answers you're posting by reading the question carefully. – rayryeng Dec 10 '14 at 18:41
  • 1
    I faced the same error and I hadn't specified the extension or image format with the filename. This is the correct answer in the case of python. – Abhijay Ghildyal Apr 14 '19 at 20:59
  • I also got results in Python by using tip mentioned above, much appreciated. – El_1988 Aug 21 '19 at 10:15
  • pretty weird, but this was in my case: `out.ong` instead of `out.png`! – loretoparisi May 27 '20 at 11:43
10

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

bit_scientist
  • 1,496
  • 2
  • 15
  • 34
dannyxyz22
  • 978
  • 9
  • 18
  • Well this is interesting. The [Qt Creator build](http://i.imgur.com/Nzf0b.png) links with *opencv_core231.dll* and the [Visual Studio build](http://i.imgur.com/OAxmj.png) links with *opencv_core231d.dll*. ([Note about the DLLs.](http://stackoverflow.com/questions/9868963/cvimwrite-could-not-find-a-writer-for-the-specified-extension#comment12725201_9961035)) What's the difference between the regular and the 'd' DLL and what does that tell us about the issue? – Pieter Apr 03 '12 at 07:50
  • 1
    the one with 'd' is the debug version which gives you more debug information. The other one without 'd' is the release version that means it can generally run faster and has smaller size. You should be able to tell the compiler which dll the program needs to link. And obviously, in Qt you ask the compiler to link the release version while in VS you linked to the debug version. – james Apr 03 '12 at 12:11
  • Bingo, I figured it out... I need to link with OpenCV's debug DLLs when I'm doing a debug build or else the writeout will inexplicably fail. Thanks for the winning answer -- the bounty is yours! – Pieter Apr 03 '12 at 19:01
  • Wow, you made it, I just gave you a small clue =) Thanks for the bounty it was my first one. – dannyxyz22 Apr 04 '12 at 00:39
  • Dependency Walker is great for these scenerios. Nice answer. – saurabheights Jan 29 '16 at 07:14
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.

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 :

Ankur Bhadania
  • 4,123
  • 1
  • 23
  • 38
eatcosmos
  • 11
  • 3
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
Eric
  • 2,301
  • 3
  • 23
  • 30
  • Those are command for linux. You can easily do the same on windows using gui interface to cmake. – Eric Mar 26 '12 at 09:09
  • I followed your steps to compile OpenCV manually. The version I ended up with was v2.3.3, which is more recent than the latest stable build for Windows (v2.3.1). Sadly I still have the same issue... Here's my *Media I/O* section. It said *build* instead of *TRUE* but I figured this wouldn't be a problem. http://pastebin.com/D2LkrWGR – Pieter Mar 29 '12 at 09:30
  • Oh, and [this](http://i.imgur.com/nwq5T.png) has also been happening to me. Code snippet [here](http://pastebin.com/9vAgPv93). – Pieter Mar 29 '12 at 11:54
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.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • That works for me in Visual Studio, but I'm using the Qt Creator IDE with the MSVC2010 compiler. Here are the my include path and the associated library flags: http://pastebin.com/jj7damtx I copied all DLLs in *C:\opencv\build\x86\vc10\bin* to the directory of the program I'm trying to build. The article said to rename the *opencv* directory to *OpenCV 2.3.1* but since VS2010 worked without this step I'm assuming it didn't get in the way of Qt Creator either. – Pieter Apr 01 '12 at 07:44
  • Just so you know where everything is stored on my computer, here are the environment variables the helper program made: OPENCV = C:\opencv, PATH = %OPENCV%\build\x86\vc10\bin, LIB = %OPENCV%\build\x86\vc10\lib, INCLUDE = %OPENCV%\build\include. – Pieter Apr 01 '12 at 07:45