Can I use good feature to track if I have the training data is a landmark point? [closed]

asked 2017-06-21 12:26:49 -0600

Shabrina gravatar image

updated 2017-06-21 12:27:55 -0600

I have matrix that is the training data. The content of the data is point landmark. the data that save in rt matrix. then, I have new image from src matrix.

 void mean(Mat src){
    Mat rt, simpan, cascade;
    Point pt=Point2f(x,y), sm;
    FileStorage sv0("mall.txt", cv::FileStorage::READ);
    mens = sv0["Point"];
    read(mens,rt);

    Mat img_1 = rt;
    Mat img_2 = src;
  int minHessian = 400;

  SurfFeatureDetector detector( minHessian );

  std::vector<KeyPoint> keypoints_1, keypoints_2;

  detector.detect( img_1, keypoints_1 );
  detector.detect( img_2, keypoints_2 );

  //-- Step 2: Calculate descriptors (feature vectors)
  SurfDescriptorExtractor extractor;

  Mat descriptors_1, descriptors_2;

  extractor.compute( img_1, keypoints_1, descriptors_1 );
  extractor.compute( img_2, keypoints_2, descriptors_2 );

  //-- Step 3: Matching descriptor vectors using FLANN matcher
  FlannBasedMatcher matcher;
  std::vector< DMatch > matches;
  matcher.match( descriptors_1, descriptors_2, matches );

  double max_dist = 0; double min_dist = 100;

  //-- Quick calculation of max and min distances between keypoints
  for( int i = 0; i < descriptors_1.rows; i++ )
  { double dist = matches[i].distance;
    if( dist < min_dist ) min_dist = dist;
    if( dist > max_dist ) max_dist = dist;
  }

  printf("-- Max dist : %f \n", max_dist );
  printf("-- Min dist : %f \n", min_dist );

  std::vector< DMatch > good_matches;

  for( int i = 0; i < descriptors_1.rows; i++ )
  { if( matches[i].distance <= max(2*min_dist, 0.02) )
    { good_matches.push_back( matches[i]); }
  }

  //-- Draw only "good" matches
  Mat img_matches;
  drawMatches( img_1, keypoints_1, img_2, keypoints_2,
               good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
               vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

  //-- Show detected matches
  imshow( "Good Matches", img_matches );

  for( int i = 0; i < (int)good_matches.size(); i++ )
  { printf( "-- Good Match [%d] Keypoint 1: %d  -- Keypoint 2: %d  \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx ); }


    //imshow("Segmentasi",src);
}

I will track the new image with the training data, but the code was be break. this is the image image description

the data training is red color. and this is the error

OpenCV Error: Assertion failed (!img.empty() && img.depth() == CV_8U) in cv::SURF::operator (), file ........\opencv\modules\nonfree\src\surf.cpp,

thank you.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-08 10:01:50.808903