src/matching2D_Student.cpp
// Use one of several types of state-of-art descriptors to uniquely identify keypoints
Use one of several types of state-of-art descriptors to uniquely identify keypoints
Use one of several types of state - of - art descriptors to uniquely identify keypoints
void descKeypoints(vector<cv::KeyPoint> &keypoints, cv::Mat &img, cv::Mat &descriptors, string descriptorType)
{
  cv::Ptr<cv::DescriptorExtractor> extractor;
  if (descriptorType == "BRISK")
  {
    int threshold = 30;        
    int octaves = 3;           
    float patternScale = 1.0f; 
    extractor = cv::BRISK::create(threshold, octaves, patternScale);
  }
  else if (descriptorType == "BRIEF")
  {
    int bytes = 32;               
    bool use_orientation = false; 
    extractor = cv::xfeatures2d::BriefDescriptorExtractor::create(bytes, use_orientation);
  }
  else if (descriptorType == "ORB")
  {
    int   nfeatures = 500;     
    float scaleFactor = 1.2f;  
    int   nlevels = 8;         
    int   edgeThreshold = 31;  
    int   firstLevel = 0;      
    int   WTA_K = 2;           
    auto  scoreType = cv::ORB::HARRIS_SCORE; 
    int   patchSize = 31;      
    int   fastThreshold = 20;  
    extractor = cv::ORB::create(nfeatures, scaleFactor, nlevels, edgeThreshold,
                                firstLevel, WTA_K, scoreType, patchSize, fastThreshold);
  }
  else if (descriptorType == "FREAK")
  {
    bool orientationNormalized = true; 
    bool scaleNormalized = true;       
    float patternScale = 22.0f;        
    int nOctaves = 4;                  
    const std::vector<int>& selectedPairs = std::vector<int>(); 
    extractor = cv::xfeatures2d::FREAK::create(orientationNormalized, scaleNormalized, patternScale,
                                               nOctaves, selectedPairs);
  }
  else if (descriptorType == "AKAZE")
  {
    auto  descriptor_type = cv::AKAZE::DESCRIPTOR_MLDB;
    int   descriptor_size = 0;        
    int   descriptor_channels = 3;    
    float threshold = 0.001f;         
    int   nOctaves = 4;               
    int   nOctaveLayers = 4;          
    auto  diffusivity = cv::KAZE::DIFF_PM_G2; 
    extractor = cv::AKAZE::create(descriptor_type, descriptor_size, descriptor_channels,
                                  threshold, nOctaves, nOctaveLayers, diffusivity);
  }
  else if (descriptorType == "SIFT")
  {
    int nfeatures = 0; 
    int nOctaveLayers = 3; 
    double contrastThreshold = 0.04;
    double edgeThreshold = 10; 
    double sigma = 1.6; 
    extractor = cv::xfeatures2d::SIFT::create(nfeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma);
  }
  else
  {
    throw std::invalid_argument("unknown descriptor type: " + descriptorType);
  }
  auto t = static_cast<double>(cv::getTickCount());
  extractor->compute(img, keypoints, descriptors);
  t = (static_cast<double>(cv::getTickCount()) - t) / cv::getTickFrequency();
  cout << descriptorType << " descriptor extraction in " << 1000 * t / 1.0 << " ms" << endl;
  fstream ofs;
  ofs.open(descriptorType + "_descriptor_timings.txt", std::ios::app);
  ofs << 1000 * t / 1.0 << '\n';
  ofs.close();
}
void descKeypoints ( vector < cv :: KeyPoint > & keypoints , cv :: Mat & img , cv :: Mat & descriptors , string descriptorType ) { cv :: Ptr < cv :: DescriptorExtractor > extractor ; if ( descriptorType == " " ) { int threshold = 30 ; int octaves = 3 ; float patternScale = 1.0f ; extractor = cv :: BRISK :: create ( threshold , octaves , patternScale ) ; } else if ( descriptorType == " " ) { int bytes = 32 ; bool use_orientation = false ; extractor = cv :: xfeatures2d :: BriefDescriptorExtractor :: create ( bytes , use_orientation ) ; } else if ( descriptorType == " " ) { int nfeatures = 500 ; float scaleFactor = 1.2f ; int nlevels = 8 ; int edgeThreshold = 31 ; int firstLevel = 0 ; int WTA_K = 2 ; auto scoreType = cv :: ORB :: HARRIS_SCORE ; int patchSize = 31 ; int fastThreshold = 20 ; extractor = cv :: ORB :: create ( nfeatures , scaleFactor , nlevels , edgeThreshold , firstLevel , WTA_K , scoreType , patchSize , fastThreshold ) ; } else if ( descriptorType == " " ) { bool orientationNormalized = true ; bool scaleNormalized = true ; float patternScale = 22.0f ; int nOctaves = 4 ; const std :: vector < int > & selectedPairs = std :: vector < int > ( ) ; extractor = cv :: xfeatures2d :: FREAK :: create ( orientationNormalized , scaleNormalized , patternScale , nOctaves , selectedPairs ) ; } else if ( descriptorType == " " ) { auto descriptor_type = cv :: AKAZE :: DESCRIPTOR_MLDB ; int descriptor_size = 0 ; int descriptor_channels = 3 ; float threshold = 0.001f ; int nOctaves = 4 ; int nOctaveLayers = 4 ; auto diffusivity = cv :: KAZE :: DIFF_PM_G2 ; extractor = cv :: AKAZE :: create ( descriptor_type , descriptor_size , descriptor_channels , threshold , nOctaves , nOctaveLayers , diffusivity ) ; } else if ( descriptorType == " " ) { int nfeatures = 0 ; int nOctaveLayers = 3 ; double contrastThreshold = 0.04 ; double edgeThreshold = 10 ; double sigma = 1.6 ; extractor = cv :: xfeatures2d :: SIFT :: create ( nfeatures , nOctaveLayers , contrastThreshold , edgeThreshold , sigma ) ; } else { throw std :: invalid_argument ( " " + descriptorType ) ; } auto t = static_cast < double > ( cv :: getTickCount ( ) ) ; extractor -> compute ( img , keypoints , descriptors ) ; t = ( static_cast < double > ( cv :: getTickCount ( ) ) - t ) / cv :: getTickFrequency ( ) ; cout << descriptorType << " " << 1000 * t / 1.0 << " " << endl ; fstream ofs ; ofs . open ( descriptorType + " " , std :: ios :: app ) ; ofs << 1000 * t / 1.0 << ' \n ' ; ofs . close ( ) ; }
Use one of several types of state-of-art descriptors to uniquely identify keypoints
Use one of several types of state - of - art descriptors to uniquely identify keypoints
// select appropriate descriptor // FAST/AGAST detection threshold score. // detection octaves (use 0 to do single scale) // apply this scale to the pattern used for sampling the neighbourhood of a keypoint. // legth of the descriptor in bytes // sample patterns using key points orientation // The maximum number of features to retain. // Pyramid decimation ratio, greater than 1. // The number of pyramid levels. // This is size of the border where the features are not detected. // The level of pyramid to put source image to. // The number of points that produce each element of the oriented BRIEF descriptor. // HARRIS_SCORE / FAST_SCORE algorithm is used to rank features. // Size of the patch used by the oriented BRIEF descriptor. // The FAST threshold. // Enable orientation normalization. // Enable scale normalization. // Scaling of the description pattern. // Number of octaves covered by the detected keypoints. // (Optional) user defined selected pairs indexes. // Type of the extracted descriptor: DESCRIPTOR_KAZE, DESCRIPTOR_KAZE_UPRIGHT, //                                   DESCRIPTOR_MLDB or DESCRIPTOR_MLDB_UPRIGHT. // Size of the descriptor in bits. 0 -> Full size // Number of channels in the descriptor (1, 2, 3). //   Detector response threshold to accept point. // Maximum octave evolution of the image. // Default number of sublevels per scale level. // Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, //                   DIFF_WEICKERT or DIFF_CHARBONNIER. // The number of best features to retain. // The number of layers in each octave. 3 is the value used in D. Lowe paper. // The contrast threshold used to filter out weak features in semi-uniform (low-contrast) regions. // The threshold used to filter out edge-like features. // The sigma of the Gaussian applied to the input image at the octave \#0. // perform feature description