Reputation: 210
I am using these codes for encode Mat image to .jpg format. It is working with small images, but when I put a large image, project give exception
Unhandled exception at 0x76377fb2 (ucrtbase.dll) in ImageRecognition.exe: 0xC0000409: 0xc0000409.
I am using opencv2.4.12 in Visual Studio 2015 and my OS is Windows 10 here is my code block.
cv::threshold(image, image, 100, 255, cv::THRESH_BINARY + cv::THRESH_OTSU);
std::vector<uchar> buf;
imencode(".jpg", image, buf);
Upvotes: 4
Views: 14533
Reputation: 210
Some opportunities to solve this problem :
try to allocate buffer before call std::vector<uchar> buf(50000);
I used this solution it is worked for me. I will upgrade my opencv version to 3.2 as soon as possible
good idea update to opencv 3.2
Upvotes: 2
Reputation: 41
try reserve memory before call imencode() :
std::vector<uchar> buffer;
#define MB 1024*1024
buffer.resize(200* MB);
cv::imencode(".png", image, buffer);
Upvotes: 2