You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cv::imwrite() always crashes when accessing the params vector (Windows 8.1 x86) #5227
When writing an image to disk (cv:imwrite) using an encoding which accesses the Vector<int>& params the code will always crash during runtime with an "Access violation". I am able to reproduce with encodings JPG and PNG. If an encoding is used which doesn't use the params vector the problem doesn't exist (e.g. BMP).
I am running Windows 8.1 Pro with Visual Studio 2013 and OpenCV from git (master). If needed I have all build settings and files stored and can rebuild/test upon request.
Second code to reproduce: std::string filename = "file.jpg"; cv::Mat image cv::Mat(600, 800, CV_8U); std::vector<int> my_params; my_params.push_back(CV_IMWRITE_JPEG_QUALITY); my_params.push_back(80); cv::imwrite(filename.c_str(), image, my_params);
A workaround is to just use a different params vector which is cleanly created inside the imwrite_ static function. This workaround FORGETS and silently IGNORES any given parameters and let's the functions fall back to any default opencv parameters for the specific image encoding.
@ilya-lavrenov the workaround is really not suitable for a merge-request as it just forgets the params given. More research is needed to determine the platform specific cause of this bug.
@kikaxa Open a new issue with complete reproducer code, crash stack trace and OpenCV build configuration.
There are many cases where imwrite is used, and it works without crashes.
after some painfull debugging, it might be the app/compiler/crt that is bugged.
it crashed with mixed debug(app)/release(opencv) modes, and a lot of other things were broken, too.
for now it works in regular build, i'll open the new bug if crash reappears.
Activity
ilya-lavrenov commentedon Aug 20, 2015
Could you create merge-request with proposed changes and regression tests?
prospo commentedon Aug 20, 2015
@ilya-lavrenov the workaround is really not suitable for a merge-request as it just forgets the params given. More research is needed to determine the platform specific cause of this bug.
prospo commentedon Aug 20, 2015
I found the following stackoverflow questions explaining they are encountering exactly this problem:
http://stackoverflow.com/questions/13496712/opencv-unhandled-exception-when-writing-a-file
http://stackoverflow.com/questions/29287117/opencv-imwrite-params-read-access-violation
Both questions are answered with a non working solution, either -DWITH-JPEG=ON or using BMP instead.
I was also able to reproduce this problem by installing the Windows opencv-3.0.0 binary installation package from the OpenCV website:
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0/opencv-3.0.0.exe/download
MaverickTse commentedon Oct 26, 2015
Just to report that an up-to-date build of OpenCV using MSVC or INTEL compiler(32bit build), No CUDA, No OpenEXR, No contrib, CAN output PNG.
It seems fixed. Confirmed with 64bit VC2013 build of OpenCV with CUDA and OpenEXR.
Dikay900 commentedon Dec 23, 2015
Can confirm this is not an issue anymore with latest sources. Using the params exactly like the reproducable code.
alalek commentedon Dec 23, 2015
Thanks for checks!
kikaxa commentedon Dec 14, 2016
can we reopen this?
i still get this same crash with msvc2010, opencv 3.1
alalek commentedon Dec 14, 2016
@kikaxa Open a new issue with complete reproducer code, crash stack trace and OpenCV build configuration.
There are many cases where
imwriteis used, and it works without crashes.kikaxa commentedon Dec 14, 2016
after some painfull debugging, it might be the app/compiler/crt that is bugged.
it crashed with mixed debug(app)/release(opencv) modes, and a lot of other things were broken, too.
for now it works in regular build, i'll open the new bug if crash reappears.
PkLab commentedon Dec 15, 2016
I've same issue (Win7, VS2013, OCV 3.1.0/x64 home build)
Both cases debug(app)/debug(opencv) and release(app)/release(opencv) work fine
I think that a new issue should be opened
alalek commentedon Dec 15, 2016
Crashes in mixed debug/release mode can't be solved in OpenCV - it is MSVS runtime specific.
PkLab commentedon Dec 16, 2016
Do you want to say that, OpenCV Release build can't be used with end user application Debug build due to MSVS runtime specific ?
any investigation might be useful also around other functions and maybe a workaround or a compiler switch exists.
...looking at imwrite here the
paramsisn't correctly assigned/initialized/linked in Debug buildAdding here a simple
The following test prints out
params.size()=184467440736......The following test prints out
params.size()=32alalek commentedon Dec 16, 2016
ABI is different in debug/release builds for most C++/STL structures, so you can't used them in mixed mode.
Please take a look on this thread in QT project:
http://www.qtcentre.org/threads/54332-Mixing-Debug-and-Release-binaries
The only thing that probably can be done in OpenCV to help users - it is to prevent successful builds (raise some error).
PkLab commentedon Dec 16, 2016
@alalek thank you very much for your useful answer. quoting the user from the referring thread