OpenCV out of memory problem on imread\imdecode
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?
Hey Did you get the solution for this.I am facing the same issue.If you can share the solution you implemented
hmm i am usually just using imread to read in the image, maybe just try this. Also check your image size.
What kind of image are you loading? - Which OS? How big is the resolution / file size?. Maybe there's no bug at all.
@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.