【问题标题】:OpenCV - print object name only when homography is drawnOpenCV - 仅在绘制单应性时打印对象名称
【发布时间】:2015-03-27 04:07:47
【问题描述】:

我有一个 OpenCV 程序,它使用 SURF 来检测是否在视频流中检测到模板对象。我希望在检测到对象时打印出对象名称,但目前它似乎正在打印,只要找到“良好”的特征匹配,在绝大多数情况下都是误报。

我的程序如下:

    //Step 1: Detect keypoints using SURF detector
    //Step 2: Calculate descriptors (feature vectors)
    //Step 3: Matching descriptor vectors using FLANN matcher
    //Step 4: Localise the object
  std::vector<Point2f> obj;
  std::vector<Point2f> scene;

  for( int i = 0; i < good_matches.size(); i++ )
  {
    //-- Get the keypoints from the good matches
    obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
    scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
  }

  Mat H = findHomography( obj, scene, CV_RANSAC );
     std::vector<Point2f> obj_corners(4);
      obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( img_object.cols, 0 );
      obj_corners[2] = cvPoint( img_object.cols, img_object.rows ); obj_corners[3] = cvPoint( 0, img_object.rows );
      std::vector<Point2f> scene_corners(4);

      perspectiveTransform( obj_corners, scene_corners, H);

      //-- Draw lines between the corners (the mapped object in the scene - image_2 )
      line( img_matches, scene_corners[0] + Point2f( img_object.cols, 0), scene_corners[1] + Point2f( img_object.cols, 0), Scalar(0, 255, 0), 4 );
      line( img_matches, scene_corners[1] + Point2f( img_object.cols, 0), scene_corners[2] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
      line( img_matches, scene_corners[2] + Point2f( img_object.cols, 0), scene_corners[3] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
      line( img_matches, scene_corners[3] + Point2f( img_object.cols, 0), scene_corners[0] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );

      if() {
        std::cout << fileNamePostCut << std::endl;
      }
    ...

我不确定要说明哪个条件才能打印对象名称 (fileNamePostCut)

【问题讨论】:

    标签: c++ opencv computer-vision surf object-detection


    【解决方案1】:

    您的目标是消除误报。您应该采用两种方法:

    1. 首先,使用SIFT ratio test 忽略不明确的匹配项
    2. 您正在根据匹配项计算单应性。将其用作正确匹配的模型:cv::findHomography 有一个名为 ma​​skoptional output。使用它来确定有多少匹配实际上对单应性做出了贡献(这些被称为内点)。越多越好 - 例如,如果您有超过 10 个内点,则仅打印对象的名称。

    【讨论】:

      猜你喜欢
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 2012-09-11
      • 2015-10-28
      • 1970-01-01
      • 2023-03-22
      • 2022-12-10
      相关资源
      最近更新 更多