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.
Code to reproduce:
std::string filename = "file.png";
cv::Mat image cv::Mat(600, 800, CV_8U);
cv::imwrite(filename.c_str(), image);
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.
Open modules\imgcodecs\src\loadsave.cpp change function:
static bool imwrite_( const String& filename, const Mat& image, const std::vector<int>& params, bool flipv )
Find the following line:
bool code = encoder->write(*pimage, params);
Replace with:
//bool code = encoder->write(*pimage, params);
bool code = encoder->write(*pimage, {});
When writing an image to disk (
cv:imwrite) using an encoding which accesses theVector<int>& paramsthe 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 theparamsvector 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.
Code to reproduce:
std::string filename = "file.png";cv::Mat image cv::Mat(600, 800, CV_8U);cv::imwrite(filename.c_str(), image);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
paramsvector which is cleanly created inside theimwrite_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.Open
modules\imgcodecs\src\loadsave.cppchange function:static bool imwrite_( const String& filename, const Mat& image, const std::vector<int>& params, bool flipv )Find the following line:
bool code = encoder->write(*pimage, params);Replace with:
//bool code = encoder->write(*pimage, params);bool code = encoder->write(*pimage, {});