[英]OpenCv, Insufficient memory error
I created this code in Opencv and after about 900 frames, this error appears: 我在Opencv中创建了此代码,大约900帧后,出现此错误:
OpenCV Error: Insufficient memory (Failed to allocate 921600 bytes) in function, file ..\..\..\..\ocv\opencv\src\cxcore\cxalloc.cpp, line 52
but I have initialized the variables once. 但是我已经初始化了一次变量。 Here is the code: 这是代码:
int _tmain(int argc, _TCHAR* argv[])
{
IplImage * image;
CvCapture * capture = cvCaptureFromCAM ( 0 );
while ( 1 ){
image = cvCreateImage ( cvSize ( 640,480 ) , 8, 3 );
image = cvQueryFrame ( capture );
cvShowImage ( "test", image );
cvWaitKey ( 10 );
}
}
You're constantly creating new images with cvCreateImage
without using and, more importantly, without releasing them anywhere. 您正在不断使用cvCreateImage
创建新映像,而无需使用它们,更重要的是,无需将它们释放到任何地方。
Just remove this line (it does not do anything other than eat up your memory): 只需删除此行(除了消耗内存,它不会做任何其他事情):
image = cvCreateImage ( cvSize ( 640,480 ) , 8, 3 );
您有时需要调用cvReleaseImage
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.