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;

for(unsigned int i = 0; i < trainFilenames.size(); i++){

    Mat sceneImage;
    std::vector<KeyPoint> sceneKeypoints;

    sceneImage = imread(, CV_LOAD_IMAGE_GRAYSCALE );

    detector.detect( sceneImage, sceneKeypoints );


std::string sceneImageData = "sceneImagedatamodel.xml";
FileStorage fs(sceneImageData, FileStorage::WRITE);

descriptorMatcher->add(allTrainImages, allKeypoints);




However, the only thing I obtain in the output file is this:

    <?xml version="1.0"?>

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.


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:

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