1

A very simple question...why am I getting a read access violation error with this code?

cv::Mat laserSpeckle = Mat::zeros(100,100,CV_8UC1);
imwrite( "C://testimage.jpg", laserSpeckle );

When i attach a debugger and look into it further, it throws the exception at this snippet in grfmt.cpp.

if( params[i] == CV_IMWRITE_JPEG_QUALITY )
        {
            quality = params[i+1];
            quality = MIN(MAX(quality, 0), 100);
        }

It occurs with .png and .tiff too. Im an OpenCV newbie, my apologies if this is something really simple. I am using Qt for what its worth.

11
  • Why does the destination path has two forward slashes (//)? Windows addresses paths with back slash (), but since it is the "escape" character on programming, we have to use two of them together "\\". Commented Mar 26, 2015 at 19:41
  • my mistake...changing them to two backslashes made no difference though. Commented Mar 26, 2015 at 19:46
  • Windows can use forward slashes for most file operations unless you need the extended path lengths using the ` "\\?\"` prefix. Commented Mar 26, 2015 at 19:50
  • Did you try using one forward slash only? Commented Mar 26, 2015 at 19:51
  • 2
    are you compiling in debug or release mode? are you linking against debug or release mode of openCV libraries? Commented Mar 27, 2015 at 8:59

5 Answers 5

2

Do you build OpenCV yourself? If yes, make sure that the option WITH_JPEG is enabled when you configure your build files:

cmake ... -DWITH_JPEG=ON ...
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to save image with alpha channel you should use png format. It is described here

Comments

0

It should work with bmp format:

cv::Mat laserSpeckle = cv::Mat::zeros(100,100,CV_8UC1);
cv::imwrite( "C://testimage.bmp", laserSpeckle );

Your code also works on my computer. However, it seems that on some systems it works only for bmp images. I saw similar issues reported here and here.

Comments

0

The problem is with the debugger version (x64) if you build the code using the release version (x64) it works fine for me.

Comments

0

In my case c++ Code Generation settings were wrong Should have been Multithreaded DEBUG dll MD

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.