{"action":"opened","issue":{"url":"https://api.github.com/repos/Itseez/opencv/issues/5227","labels_url":"https://api.github.com/repos/Itseez/opencv/issues/5227/labels{/name}","comments_url":"https://api.github.com/repos/Itseez/opencv/issues/5227/comments","events_url":"https://api.github.com/repos/Itseez/opencv/issues/5227/events","html_url":"https://github.com/Itseez/opencv/issues/5227","id":102115616,"number":5227,"title":"cv::imwrite() always crashes when accessing the params vector (Windows 8.1 x86)","user":{"login":"mielleman","id":651107,"avatar_url":"https://avatars.githubusercontent.com/u/651107?v=3","gravatar_id":"","url":"https://api.github.com/users/mielleman","html_url":"https://github.com/mielleman","followers_url":"https://api.github.com/users/mielleman/followers","following_url":"https://api.github.com/users/mielleman/following{/other_user}","gists_url":"https://api.github.com/users/mielleman/gists{/gist_id}","starred_url":"https://api.github.com/users/mielleman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mielleman/subscriptions","organizations_url":"https://api.github.com/users/mielleman/orgs","repos_url":"https://api.github.com/users/mielleman/repos","events_url":"https://api.github.com/users/mielleman/events{/privacy}","received_events_url":"https://api.github.com/users/mielleman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-20T11:06:03Z","updated_at":"2015-08-20T11:06:03Z","closed_at":null,"body":"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).\r\n\r\nI 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.\r\n\r\nCode to reproduce:\r\n`std::string filename = \"file.png\";`\r\n`cv::Mat image cv::Mat(600, 800, CV_8U);`\r\n`cv::imwrite(filename.c_str(), image);`\r\n\r\nSecond code to reproduce:\r\n`std::string filename = \"file.jpg\";`\r\n`cv::Mat image cv::Mat(600, 800, CV_8U);`\r\n`std::vector<int> my_params;`\r\n`my_params.push_back(CV_IMWRITE_JPEG_QUALITY);`\r\n`my_params.push_back(80);`\r\n`cv::imwrite(filename.c_str(), image, my_params);`\r\n\r\nA 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._\r\n\r\nOpen `modules\\imgcodecs\\src\\loadsave.cpp` change function:\r\n`static bool imwrite_( const String& filename, const Mat& image, const std::vector<int>& params, bool flipv )`\r\nFind the following line:\r\n`bool code = encoder->write(*pimage, params);`\r\nReplace with:\r\n`//bool code = encoder->write(*pimage, params);`\r\n`bool code = encoder->write(*pimage, {});`"}}