Ask Your Question
0

imencode() buffer exception [closed]

asked 2017-01-13 08:53:48 -0600

renV gravatar image

updated 2017-01-13 09:43:41 -0600

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);
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2017-01-19 01:47:36.332538

Comments

In opencv 3.2 there is no problem with your code. Check image size and channels

cv::threshold(image, image, 100, 255, cv::THRESH_BINARY + cv::THRESH_OTSU);
cout<< image.size();
cout<< image.channels();

std::vector<uchar> buf;
imencode(".jpg", image, buf);

check dll you have to use release dll in release mode and debug dll in debug mode

What size is a small image?

LBerger gravatar imageLBerger ( 2017-01-13 14:53:28 -0600 )edit

Firstly thanks for your reply LBerger. Checked what you said. Small image size : [86 x 39] Channel : 1 it is working with this image Large image size . [194 x 180] Channel : 1 it has gave exception with this and larger images All dll's imported for release mode i checked again with your advice

When project give exception it's showing from Microsoft Visual Studio 14.0\VC\include\vector's this line;

        this->_Getal().deallocate(this->_Myfirst(),
renV gravatar imagerenV ( 2017-01-13 15:41:03 -0600 )edit

Thanks for your reply LBerger. your first bad idea solved my problem. I will upgrade my project to opencv3.2 as soon as possible for more clear solution.

renV gravatar imagerenV ( 2017-01-19 01:38:08 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-14 02:23:27 -0600

LBerger gravatar image

Some (bad idea) to solve your problem :

  1. try to allocate buffer before call std::vector<uchar> buf(50000);
  2. use color image

    vector<mat> x; x.push_back(image);x.push_back(image);x.push_back(image); merge (x,y); imencode(".jpg", y, buf);

good idea update to opencv 3.2

in github I can not find update in 2.4.12 to 2.4.13.2 Can you give stack trace?

my dll in debug mode is C:\Windows\System32\ucrtbased.dll

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-13 08:53:48 -0600

Seen: 2,012 times

Last updated: Jan 13 '17