Guest User

Untitled

a guest
Aug 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. Save opencv descriptor matcher after training with Ferns descriptor
  2. int main(int argc, char** argv) {
  3.  
  4.  
  5. vector<string> trainFilenames;
  6. readTrainFilenames(modelImagesList, imagesDir, trainFilenames);
  7.  
  8. Ptr<GenericDescriptorMatcher> descriptorMatcher = GenericDescriptorMatcher::create("FERN", params_filename);
  9.  
  10. SurfFeatureDetector detector(500);
  11. SurfDescriptorExtractor extractor;
  12.  
  13. vector<vector<KeyPoint> > allKeypoints;
  14. vector<Mat> allTrainImages;
  15.  
  16. //TRAIN AND SAVE
  17. for(unsigned int i = 0; i < trainFilenames.size(); i++){
  18.  
  19. Mat sceneImage;
  20. std::vector<KeyPoint> sceneKeypoints;
  21.  
  22. sceneImage = imread(trainFilenames.at(i), CV_LOAD_IMAGE_GRAYSCALE );
  23.  
  24. detector.detect( sceneImage, sceneKeypoints );
  25.  
  26. allKeypoints.push_back(sceneKeypoints);
  27. allTrainImages.push_back(sceneImage);
  28. }
  29.  
  30. std::string sceneImageData = "sceneImagedatamodel.xml";
  31. FileStorage fs(sceneImageData, FileStorage::WRITE);
  32.  
  33. descriptorMatcher->add(allTrainImages, allKeypoints);
  34.  
  35. descriptorMatcher->train();
  36. descriptorMatcher->write(fs);
  37.  
  38. fs.release();
  39.  
  40. <?xml version="1.0"?>
  41. <opencv_storage>
  42. <nclasses>0</nclasses>
  43. <patchSize>31</patchSize>
  44. <signatureSize>2147483647</signatureSize>
  45. <nstructs>50</nstructs>
  46. <structSize>9</structSize>
  47. <nviews>1000</nviews>
  48. <compressionMethod>0</compressionMethod>
  49. </opencv_storage>
  50.  
  51. void FernDescriptorMatcher::write( FileStorage& fs ) const
  52. {
  53. fs << "nclasses" << params.nclasses;
  54. fs << "patchSize" << params.patchSize;
  55. fs << "signatureSize" << params.signatureSize;
  56. fs << "nstructs" << params.nstructs;
  57. fs << "structSize" << params.structSize;
  58. fs << "nviews" << params.nviews;
  59. fs << "compressionMethod" << params.compressionMethod;
  60.  
  61. // classifier->write(fs);
  62. }
Add Comment
Please, Sign In to add comment