简体   繁体   中英

OpenCv, Insufficient memory error

I created this code in Opencv and after about 900 frames, this error appears:

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.

Just remove this line (it does not do anything other than eat up your memory):

image = cvCreateImage ( cvSize ( 640,480 ) , 8, 3 );

您有时需要调用cvReleaseImage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM