Save opencv descriptor matcher after training with Ferns descriptor

I am working in a image recognition application and trying to implement a method using the Ferns descriptor matcher.

I training the Ferns structures and saving them using the code below:

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 obtain in the output file is this:

    <?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>

Wasn't I supposed to save the entire structure in the xml file?

I can't seem to find any where someone doing this with the new C++ interface. Are these methods really working? If so, do you guys have any idea how to put it to work?

Thank you.

Answers


I think I found the problem. I had a look at the source file and the line that actually saves the classifier 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 to the source file: https://code.ros.org/svn/opencv/trunk/opencv/modules/features2d/src/matchers.cpp

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


Need Your Help

NVelocity (or Velocity) as a stand-alone formula evaluator

c# .net velocity nvelocity

I am using NVelocity in my application to generate html emails. My application has an event-driven model, where saving and/or updating of objects causes these emails to be sent out. Each event can

Handling NEWLINE in DelimitedRecord with Filehelpers

c# parsing csv newline filehelpers

Am using the excellent FileHelpers library to parse a number of different files. One of these files has (some) lines that look like this