Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCv Memory clearing for reuse
    primarykey
    data
    text
    <p>I have a problem with the memory management in openCV after using the function:</p> <p>cvCreateMemStorage(0);</p> <p>Here is what i want to do: I am looping on the many image and I am using cvExtractSurf() to extract the keypoints and descriptors. I do that for every frame and for every two frames i am doing a certain processing. I only need to keep two frames in memory so I created memory storage using: </p> <p>cvCreateMemStorage(0);</p> <p>I would like once the processing done on each frame to completely clean the memory storage in order to reuse it to store the keypoints and descriptors of the next frame to come. I need to do that because I am processing a lot of frames and therefore creating a memory storage of a huge amount is not the best option.</p> <p>I tried to use cvClearMemStorage(), cvClearSeq() and cvRelease() but nothing work and I always end up with errors. Here is the code with the important part (i have removed all the line not directly related to the questin so of course this code wont compile):</p> <pre><code>CvMemStorage* storageSrc = cvCreateMemStorage(0); CvMemStorage* storageDest = cvCreateMemStorage(0); // loop on all .bmp files in the selected directory cout &lt;&lt; "STARTING READING THE FRAME" &lt;&lt; endl; while(myHandle!=INVALID_HANDLE_VALUE &amp;&amp; myFile.cFileName!= buffer){ buffer=myFile.cFileName; fileLocation = dirName + buffer; frameNames.push_back(fileLocation); frame = cvLoadImage(fileLocation.c_str(), CV_LOAD_IMAGE_COLOR); frameResized = cvCreateImage(cvSize(processingSizeX, processingSizeY), 8, 3); cvResize(frame, frameResized, CV_INTER_AREA); resizedGray = cvCreateImage(cvSize(processingSizeX, processingSizeY), 8, 1); cvCvtColor( frameResized, resizedGray, CV_RGB2GRAY ); if(!frame){ fprintf(stderr, "Error when loading the images."); exit(-1); } if(nbFrameRead == 0){ cout &lt;&lt; endl; cout &lt;&lt; "ZONE 1" &lt;&lt; endl; cout &lt;&lt; endl; cvSetImageROI( correspond, cvRect( 0, 0, processingSizeX, processingSizeY) ); cvCopy( frameResized, correspond ); cvResetImageROI( correspond ); cvExtractSURF( resizedGray, 0, &amp;srcFrameKeypoints, &amp;srcFrameDescriptors, storageSrc, params ); nbFrameRead++; } else if(nbFrameRead == 1){ cout &lt;&lt; endl; cout &lt;&lt; "ZONE 2" &lt;&lt; endl; cout &lt;&lt; endl; cvExtractSURF( resizedGray, 0, &amp;destFrameKeypoints, &amp;destFrameDescriptors, storageDest, params ); //printf("Nb Key Points in frame %d: %d\n", nbFrameRead, srcFrameDescriptors-&gt;total); // clear memory and switch current frame to last frame cvClearSeq(srcFrameKeypoints); cvClearSeq(srcFrameDescriptors); cvClearSeq(descriptorsOrderedSrc); cvClearMemStorage(storageSrc); srcFrameKeypoints = cvCloneSeq(destFrameKeypoints, storageSrc); descriptorsOrderedSrc = cvCloneSeq(descriptorsOrderedDest, storageSrc); cvClearSeq(destFrameKeypoints); cvClearSeq(destFrameDescriptors); cvClearSeq(descriptorsOrderedDest); cvClearMemStorage(storageDest); cvSetImageROI( correspond, cvRect( 0, 0, processingSizeX, processingSizeY) ); cvCopy( frameResized, correspond ); cvResetImageROI( correspond ); nbFrameRead++; } else if(nbFrameRead &lt; bufferSize + 2){ cout &lt;&lt; endl; cout &lt;&lt; "ZONE 3" &lt;&lt; endl; cout &lt;&lt; endl; cvExtractSURF( resizedGray, 0, &amp;destFrameKeypoints, &amp;destFrameDescriptors, storageDest, params ); //printf("Nb Key Points in frame %d: %d\n", nbFrameRead, srcFrameDescriptors-&gt;total); //clear memory and switch current frame to last frame cvClearSeq(srcFrameKeypoints); cvClearSeq(srcFrameDescriptors); cvClearSeq(descriptorsOrderedSrc); cvClearMemStorage(storageSrc); srcFrameKeypoints = cvCloneSeq(destFrameKeypoints, storageSrc); descriptorsOrderedSrc = cvCloneSeq(descriptorsOrderedDest, storageSrc); cvClearSeq(destFrameKeypoints); cvClearSeq(destFrameDescriptors); cvClearSeq(descriptorsOrderedDest); cvClearMemStorage(storageDest); nbFrameRead++; } else{ cout &lt;&lt; endl; cout &lt;&lt; "ZONE 4" &lt;&lt; endl; cout &lt;&lt; endl; cvExtractSURF( resizedGray, 0, &amp;destFrameKeypoints, &amp;destFrameDescriptors, storageDest, params ); // clear memory and switch current frame to last frame cvClearSeq(srcFrameKeypoints); cvClearSeq(srcFrameDescriptors); cvClearSeq(descriptorsOrderedSrc); cvClearMemStorage(storageSrc); srcFrameKeypoints = cvCloneSeq(destFrameKeypoints, storageSrc); descriptorsOrderedSrc = cvCloneSeq(descriptorsOrderedDest, storageSrc); cvClearSeq(destFrameKeypoints); cvClearSeq(destFrameDescriptors); cvClearSeq(descriptorsOrderedDest); cvClearMemStorage(storageDest); nbFrameRead++; nbFrameSmoothed++; } FindNextFile(myHandle,&amp;myFile); } </code></pre> <p>Is there anything wrong in this code ? If yes, what should I do to be able to completely clean storageSrc and storageDest in order to reuse it as many time as needed?</p> <p>Thank you in advance for your answer.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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