src/matching2D_Student.cpp
// Detect keypoints in image using the traditional Shi-Thomasi detector
Detect keypoints in image using the traditional Shi-Thomasi detector
Detect keypoints in image using the traditional Shi - Thomasi detector
void detKeypointsShiTomasi(vector<cv::KeyPoint> &keypoints, cv::Mat &img, bool bVis)
{
  int blockSize = 4;       
  double maxOverlap = 0.0; 
  double minDistance = (1.0 - maxOverlap) * blockSize;
  int maxCorners = img.rows * img.cols / max(1.0, minDistance); 
  double qualityLevel = 0.01; 
  double k = 0.04;
  auto t = static_cast<double>(cv::getTickCount());
  vector<cv::Point2f> corners{};
  cv::goodFeaturesToTrack(img, corners, maxCorners, qualityLevel, minDistance, cv::Mat(), blockSize, false, k);
  for (auto& corner : corners)
  {
    cv::KeyPoint newKeyPoint;
    newKeyPoint.pt = cv::Point2f(corner.x, corner.y);
    newKeyPoint.size = blockSize;
    keypoints.push_back(newKeyPoint);
  }
  t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
  cout << "Shi-Tomasi detection with n=" << keypoints.size() << " keypoints in " << 1000 * t / 1.0 << " ms" << endl;
  fstream ofs;
  ofs.open("SHITOMASI_detector_timings.txt", std::ios::app);
  ofs << 1000 * t / 1.0 << '\n';
  ofs.close();
  if (bVis)
  {
    cv::Mat visImage = img.clone();
    cv::drawKeypoints(img, keypoints, visImage, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    std::string windowName = "Shi-Tomasi Corner Detector Results";
    cv::namedWindow(windowName, 6);
    imshow(windowName, visImage);
    cv::waitKey(0);
  }
}
void detKeypointsShiTomasi ( vector < cv :: KeyPoint > & keypoints , cv :: Mat & img , bool bVis ) { int blockSize = 4 ; double maxOverlap = 0.0 ; double minDistance = ( 1.0 - maxOverlap ) * blockSize ; int maxCorners = img . rows * img . cols / max ( 1.0 , minDistance ) ; double qualityLevel = 0.01 ; double k = 0.04 ; auto t = static_cast < double > ( cv :: getTickCount ( ) ) ; vector < cv :: Point2f > corners { } ; cv :: goodFeaturesToTrack ( img , corners , maxCorners , qualityLevel , minDistance , cv :: Mat ( ) , blockSize , false , k ) ; for ( auto & corner : corners ) { cv :: KeyPoint newKeyPoint ; newKeyPoint . pt = cv :: Point2f ( corner . x , corner . y ) ; newKeyPoint . size = blockSize ; keypoints . push_back ( newKeyPoint ) ; } t = ( ( double ) cv :: getTickCount ( ) - t ) / cv :: getTickFrequency ( ) ; cout << " " << keypoints . size ( ) << " " << 1000 * t / 1.0 << " " << endl ; fstream ofs ; ofs . open ( " " , std :: ios :: app ) ; ofs << 1000 * t / 1.0 << ' \n ' ; ofs . close ( ) ; if ( bVis ) { cv :: Mat visImage = img . clone ( ) ; cv :: drawKeypoints ( img , keypoints , visImage , cv :: Scalar :: all ( -1 ) , cv :: DrawMatchesFlags :: DRAW_RICH_KEYPOINTS ) ; std :: string windowName = " " ; cv :: namedWindow ( windowName , 6 ) ; imshow ( windowName , visImage ) ; cv :: waitKey ( 0 ) ; } }
Detect keypoints in image using the traditional Shi-Thomasi detector
Detect keypoints in image using the traditional Shi - Thomasi detector
// compute detector parameters based on image size //  size of an average block for computing a derivative covariation matrix over each pixel neighborhood // max. permissible overlap between two features in % // max. num. of keypoints // minimal accepted quality of image corners // Apply corner detection // add corners to result vector // visualize results