Ask Your Question
0

save png with imwrite() - read access violation

asked 2016-04-20 06:07:49 -0600

Photonik gravatar image

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 flag offensive close merge delete

Comments

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)

berak gravatar imageberak ( 2016-04-20 07:16:30 -0600 )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.

Photonik gravatar imagePhotonik ( 2016-05-20 03:39:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-20 07:14:12 -0600

Photonik gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 4,832 times

Last updated: May 20 '16