Hello,
I want to extract SURF points and create an XML with the information from a series of keyframes of a video.
This is the function that does the work:
void xVideo::extractSURFDescriptor(int f1){
ofxXmlSettings *surfXML = new ofxXmlSettings();
imageKeypoints = 0;
imageDescriptors = 0;
surfXML->addTag( "SURF" );
surfXML->pushTag( "SURF" , 0 );
ofxCvColorImage *image = new ofxCvColorImage();
image->allocate( getWidth(), getHeight() );
image->setFromPixels( getPixels(), getWidth(), getHeight() );
ofxCvGrayscaleImage *imageGray = new ofxCvGrayscaleImage();
imageGray->allocate( image->getWidth(), image->getHeight() );
imageGray->setFromColorImage( *image );
cvExtractSURF( imageGray->getCvImage(), 0, &imageKeypoints, &imageDescriptors, storage, params );
CvSeqReader reader, kreader;
cvStartReadSeq( imageKeypoints, &kreader );
cvStartReadSeq( imageDescriptors, &reader );
int len = (int) ( imageDescriptors->elem_size/sizeof(float) );
for( int i = 0; i < imageDescriptors->total ; i++ ){
const CvSURFPoint* kp = (const CvSURFPoint*)kreader.ptr;
surfXML->addTag( "INFO" );
surfXML->pushTag( "INFO" , i );
surfXML->addValue( "X", kp->pt.x );
surfXML->addValue( "Y", kp->pt.y );
surfXML->addValue( "LAPLACIAN" , kp->laplacian );
const float* descriptor = (const float*)reader.ptr;
for (int d = 0 ; d < len ; d++) {
surfXML->addValue( "V", descriptor[d] );
}
surfXML->popTag();
CV_NEXT_SEQ_ELEM( kreader.seq->elem_size, kreader );
CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader );
}
surfXML->saveFile( title + "/xml/surf/s" + ofToString( f1 ) + ".xml" );
image->clear();
imageGray->clear();
cvClearMemStorage( storage );
surfXML->clear();
}
I have storage and params initialize on the class constructor
xVideo::xVideo(){
//...
storage = cvCreateMemStorage( 0 );
params = cvSURFParams( 500, 1 );
}
and on the .h of the class
CvMemStorage* storage;
CvSURFParams params;
CvSeq *imageKeypoints, *imageDescriptors;
When the program enters this function he isn’t cleaning memory, I call the clear for image, imageGray and surfXML and do the cvClearMemStorage for the storage.
Can anyone help me?
thank you
João