Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory leaks getting sub-images from video (cvGetSubRect)
    primarykey
    data
    text
    <p>i'm trying to do video windowing that is: </p> <p>show all frames from a video and also some sub-image from each frame. This sub-image can change size and be taken from a different position of the original frame.</p> <p>So , the code i've written does basically this:</p> <ol> <li><strong>cvQueryFrame</strong> to get a new image from the video</li> <li>Create a new <strong>IplImage</strong> (img) with sub-image dimensions ( window.height,window.width)</li> <li>Create a new <strong>Cvmat</strong> (mat) with sub-image dimensions ( window.height,window.width)</li> <li><strong>CvGetSubRect</strong>(originalImage,mat,window) seizes the sub-image</li> <li>transform Mat (cvMat) to img (IplImage) using <strong>cvGetImage</strong></li> </ol> <p>my problem is that for each frame i create new IplImage and cvMat which take a lot of memory and when i try to free the allocated memory I get a segmentation fault or in the case of the CvMat the allocated space does not get free (valgrind keeps telling me its definetly lost space).</p> <p>the following code does it:</p> <pre><code>int main(void){ CvCapture* capture; CvRect window; CvMat * tmp; //window size window.x=0;window.y=0;window.height=100;window.width=100; IplImage * src=NULL,*bk=NULL,* sub=NULL; capture=cvCreateFileCapture( "somevideo.wmv"); while((src=cvQueryFrame(capture))!=NULL){ cvShowImage("common",src); //get sub-image sub=cvCreateImage(cvSize(window.height,window.width),8,3); tmp =cvCreateMat(window.height, window.width,CV_8UC1); cvGetSubRect(src, tmp , window); sub=cvGetImage(tmp, sub); cvShowImage("Window",sub); //free space if(bk!=NULL) cvReleaseImage(&amp;bk); bk=sub; cvReleaseMat(&amp;tmp); cvWaitKey(20); //window dimensions changes window.width++; window.height++; } } </code></pre> <p><strong>cvReleaseMat(&amp;tmp)</strong>; does not seem to have any effect on the total amount of lost memory, valgrind reports the same amount of "definetly lost" memory if i comment or uncomment this line. </p> <p><strong>cvReleaseImage(&amp;bk);</strong> produces a segmentation fault. notice i'm trying to free the previous sub-frame which i'm backing up in the bk variable. If i comment this line the program runs smoothly but with lots of memory leaks</p> <p>i'm using ubuntu 9.10 with opencv 2.0 .</p> <p>I really need to get rid of memory leaks, can anyone explain me how to correct this or even better how to correctly perform image windowing? </p> <p>Thank you </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload