Ask Your Question
0

OpenCV out of memory problem on imread\imdecode

asked 2019-08-26 13:02:06 -0600

Crazy Sage gravatar image

I have a problem with OpenCV. I need to read from memory, rotate, resize and save some images. It happens in a thread in 32-bit app (sadly, there is limitation, due to 3rd party library, that doesn't support 64-bit).

My code looks like this:

void processImage(std::vector<char> data)
{
 cv::Mat image = cv::imdecode(data, cv::IMREAD_UNCHANGED);
 cv::rotate(image, image, image_rotation_);
 cv::imwrite(path_.toStdString(), image);
 QString preview_path = path_.replace(path_.section("/",-1),"Previews/"+path_.section("/",-1));

 cv::resize(image, image, cv::Size(preview_size_.width(), preview_size_.height()));
 cv::imwrite(preview_path.toStdString(), image);
 image.release();
}

But it crashes on 1st to 3rd call of imdecode with message

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.7) Error: Insufficient memory (Failed to allocate 150962688 bytes) in OutOfMemoryError, file C:\opencv-3.4.7\modules\core\src\alloc.cpp, line 72

Saving to disk and reading with imread leads to same problem.

My app uses around 500Mb of memory, which is definitely less than 4Gb that should be available to 32-bit app and there is about 40% of physical memory free. Is there any way to resolve such problem or maybe I'm doing something wrong?

edit retag flag offensive close merge delete

Comments

Hey Did you get the solution for this.I am facing the same issue.If you can share the solution you implemented

snsinha gravatar imagesnsinha ( 2020-06-15 05:09:04 -0600 )edit

hmm i am usually just using imread to read in the image, maybe just try this. Also check your image size.

holger gravatar imageholger ( 2020-06-15 09:14:58 -0600 )edit

What kind of image are you loading? - Which OS? How big is the resolution / file size?. Maybe there's no bug at all.

holger gravatar imageholger ( 2020-06-15 19:04:23 -0600 )edit

@snsinha it was 32-bit app problem at the end, I transferred it to 64-bit, as required sdk was released for 64-bit version.

Crazy Sage gravatar imageCrazy Sage ( 2020-11-04 21:09:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-11-04 21:08:10 -0600

Crazy Sage gravatar image

At the end it was 32-bit app problem. Luckily for me, there was required lib released in 64-bit, so I just migrated to 64-bit build.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-08-26 13:02:06 -0600

Seen: 1,841 times

Last updated: Nov 04 '20