Save the opencv descriptor after training with the Ferns descriptor

I work in an image recognition application and try to implement a method using the Ferns descriptor pattern.

I study the structure of ferns and save them using the following code:

int main(int argc, char** argv) { vector<string> trainFilenames; readTrainFilenames(modelImagesList, imagesDir, trainFilenames); Ptr<GenericDescriptorMatcher> descriptorMatcher = GenericDescriptorMatcher::create("FERN", params_filename); SurfFeatureDetector detector(500); SurfDescriptorExtractor extractor; vector<vector<KeyPoint> > allKeypoints; vector<Mat> allTrainImages; //TRAIN AND SAVE for(unsigned int i = 0; i < trainFilenames.size(); i++){ Mat sceneImage; std::vector<KeyPoint> sceneKeypoints; sceneImage = imread(trainFilenames.at(i), CV_LOAD_IMAGE_GRAYSCALE ); detector.detect( sceneImage, sceneKeypoints ); allKeypoints.push_back(sceneKeypoints); allTrainImages.push_back(sceneImage); } std::string sceneImageData = "sceneImagedatamodel.xml"; FileStorage fs(sceneImageData, FileStorage::WRITE); descriptorMatcher->add(allTrainImages, allKeypoints); descriptorMatcher->train(); descriptorMatcher->write(fs); fs.release(); 

}

However, the only thing I get in the output file is:

  <?xml version="1.0"?> <opencv_storage> <nclasses>0</nclasses> <patchSize>31</patchSize> <signatureSize>2147483647</signatureSize> <nstructs>50</nstructs> <structSize>9</structSize> <nviews>1000</nviews> <compressionMethod>0</compressionMethod> </opencv_storage> 

Shouldn't I save the whole structure in an XML file?

It seems I cannot find where anyone is doing this with the new C ++ interface. Do these methods really work? If so, do you guys know how to make it work?

Thanks.

+4
source share
1 answer

I think I found the problem. I looked at the source file, and the line that the classifier actually stores is commented out.

 void FernDescriptorMatcher::write( FileStorage& fs ) const { fs << "nclasses" << params.nclasses; fs << "patchSize" << params.patchSize; fs << "signatureSize" << params.signatureSize; fs << "nstructs" << params.nstructs; fs << "structSize" << params.structSize; fs << "nviews" << params.nviews; fs << "compressionMethod" << params.compressionMethod; // classifier->write(fs); } 

Here is the URL of the source file: https://code.ros.org/svn/opencv/trunk/opencv/modules/features2d/src/matchers.cpp

The FernClassifier class implements the write () method in the planardetect.cpp file. I do not know why this is commented. I think you could uncomment the line and recompile.

+2
source

All Articles