Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.

save png with imwrite() - read access violation

Hey there,

I already searched everything I could but only found similar problems, not a single proper solution. What I'm using: Win7 x64, QT 5.5.1 x64, VS2013 as compiler, opencv 3.1 x64 (precompiled version from the website).

I already have lots of code using opencv that works well. Only problem: writing png/jpg with imwrite while in debug mode.

#include "opencv2/opencv.hpp"
...
cv::imwrite("D:/Scans/image.png", matTemp); // crashes
cv::imwrite("D:/Scans/image.bmp", matTemp); // works fine


Error: ... code: 0xc0000005: read access violation at: 0x0, flags=0x0

As said, this only happens when trying to save JPG or PNG in DEBUG mode. Saving as bmp works fine, saving as png and jpg while in release mode works, too. So there's nothing wrong with the Mat, the saved images are ok.

What I've gathered is, that this might have to do with opencv_ffmpeg*.dll. (also I read, that 0xc0...05 usually points to problems with (wrong) dlls)

There's no debug version of that file in the opencv-dl, so it makes sense to me, that it crashes when I try to access dependent methods.

Question is, how can I use ffmpeg in debug mode? I'm not a professional programmer, nor a particularily good hobbyist - I just do image processing and work my way through programming as good as I can - so I'm happy that everything is set up and works (mostly).

Would I need to build a debug dll myself? If so, how, from what? I've no idea about that stuff. Or is there a simpler way to get it to work with what I already have?

Some mentioned copying the ffmpeg.dll in the debug folder, didn't help. ...\vc12\bin\ is registered as PATH variable, doesn't help.

I'd be very thankful, if anyone could help me with that problem. I'm out of (my very limited) ideas and would really like to solve this.

Photonik

edit retag close merge delete

please check, if you accidentally link release opencv libs to debug build

(and you can rule out opencv_ffmpeg.dll, which is only used for streaming video)

( 2016-04-20 07:16:30 -0500 )edit

Sorry for the late reply, I was very busy otherwise. For the time being I use the image save function of QT, which works, but limits me to 8bit, but I'd really need 16bit for my purposes (and don't want to use xml/yaml as alternative).

My .pro file of QT looks like this (OpenCV parts only)

INCLUDEPATH += C:\opencv\build\include

CONFIG(release,debug|release)
{
LIBS += C:\opencv\build\x64\vc12\lib\opencv_world310.lib
}

CONFIG(debug,debug|release)
{
LIBS += C:\opencv\build\x64\vc12\lib\opencv_world310d.lib
}


So I don't think I linked anything wrong. If so, please correct me; I just did, what others suggested.

( 2016-05-20 03:39:12 -0500 )edit

Sort by » oldest newest most voted

This isn't a real solution for the problem itself, but somewhere I found a way by using the C API.

cvSaveImage("image.png", &IplImage(mat) );


I don't get any errors and the images save fine in every supported format.

more

Stats

Asked: 2016-04-20 06:07:49 -0500

Seen: 2,608 times

Last updated: May 20 '16