简体   繁体   English

OpenCV写入参数读取访问冲突

[英]OpenCV imwrite params read access violation

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. 当我连接调试器并进一步查看它时,它将在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. 它也与.png和.tiff一起出现。 Im an OpenCV newbie, my apologies if this is something really simple. 我是OpenCV新手,如果这真的很简单,我深表歉意。 I am using Qt for what its worth. 我用Qt的价值。

Do you build OpenCV yourself? 您自己构建OpenCV吗? If yes, make sure that the option WITH_JPEG is enabled when you configure your build files: 如果是,请在配置构建文件时确保启用选项WITH_JPEG

cmake ... -DWITH_JPEG=ON ...

It should work with bmp format: 它应使用bmp格式:

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. 但是,似乎在某些系统上它仅适用于bmp图像。 I saw similar issues reported here and here . 我在这里这里看到了类似的问题报道。

If you want to save image with alpha channel you should use png format. 如果要使用Alpha通道保存图像,则应使用png格式。 It is described here 在这里描述

问题出在调试器 版本 (x64)上,如果您使用发行 (x64)生成代码,则对我来说效果很好。

在我的情况下,c ++代码生成设置错误,应该是多线程调试dll MD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM