如何修复内存不足错误(openCV) [英] How to fix the insufficient memory error (openCV)

查看:106
本文介绍了如何修复内存不足错误(openCV)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮忙解决这个问题:

OpenCV 错误: Insufficient memory (Failed to allocation 921604 bytes) in未知函数,文件........\ocv\opencv\modules\core\src\alloc.cpp,第 52 行

OpenCV Error: Insufficient memory (Failed to allocate 921604 bytes) in unknown function, file ........\ocv\opencv\modules\core\src\alloc.cpp, line 52

我使用 cv::clonepointer

代码是:

每100ms有一个定时器;在定时器事件中,我调用了这个方法:

There is a timer every 100ms; In the timer event, I call this method:

void DialogApplication::filterhijau(const Mat &image, Mat &result) {   
   cv::Mat resultfilter = image.clone();

   int nlhijau = image.rows;

   int nchijau = image.cols*image.channels();;

    for(int j=0; j<nlhijau; j++) {
       uchar *data2=resultfilter.ptr<uchar> (j);  //alamat setiap line pada result
       for(int i=0; i<nchijau; i++) {
          *data2++ = 0;       //element B
          *data2++ = 255;     //element G  
          *data2++ = 0;       //element R
       }
     //  free(data2);   //I add this line but the program hung up
   }

   cv::addWeighted(resultfilter,0.3,image,0.5,0,resultfilter);
   result=resultfilter;
}

推荐答案

cv::Matclone() 方法执行数据的硬拷贝.所以问题是,为每个 filterhijau() 分配一个新图像,并且在数百次调用此方法后,您的应用程序将占用数百 MB(如果不是 GB),从而抛出 内存不足错误.

The clone() method of a cv::Mat performs a hard copy of the data. So the problem is that for each filterhijau() a new image is allocated, and after hundreds of calls to this method your application will have occupied hundreds of MBs (if not GBs), thus throwing the Insufficient Memory error.

您似乎需要重新设计当前的方法,以减少占用的 RAM 内存.

It seems like you need to redesign your current approach so it occupies less RAM memory.

这篇关于如何修复内存不足错误(openCV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆