gpt4 book ai didi

c++ - OpenCV - 仅在绘制单应性时打印对象名称

转载 作者:行者123 更新时间:2023-11-28 06:27:58 24 4
gpt4 key购买 nike

我有一个 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)

最佳答案

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

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

关于c++ - OpenCV - 仅在绘制单应性时打印对象名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28189188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com