Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Save opencv descriptor matcher after training with Ferns descriptor
- 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();
- <?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>
- 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);
- }
Add Comment
Please, Sign In to add comment