【问题标题】:Function detect in Features2dFeatures2d中的功能检测
【发布时间】:2012-03-30 02:49:05
【问题描述】:

有人知道检测功能是如何工作的吗?例如这里:

Mat img = imread (...);    
SurfFeatureDetector detector(400); 
vector<KeyPoint> keypoints;
detector.detect(img, keypoints);

尤其是关键点的书写方式。

我需要在不使用的情况下在关键点中写一些坐标

detector.detect(...);

这行不通

keypoints.push_back(KeyPoint(i,j);

下一个问题: 我有这个功能:

void trajkovic(Mat img, vector<KeyPoint> keypoints)
{    for( int i = 0; i < img.rows-3; i++ )
        for( int j = 0; j < img.cols-3; j++ )
        {   Point2f keyPointLocation(i, j);
            keypoints.push_back(KeyPoint(keyPointLocation, 1)); } }

int main()
{   Mat img_object = imread( ".../box.png", CV_LOAD_IMAGE_GRAYSCALE );
    Mat img_scene = imread( ".../box_in_scene.png", CV_LOAD_IMAGE_GRAYSCALE );

    std::vector<KeyPoint> keypoints_object, keypoints_scene;
    trajkovic(img_object, keypoints_object);
    trajkovic(img_scene, keypoints_scene);
  • 而不是 (*detector.detect(img_object, keypoints_object);*)

    //-- Step 2: Calculate descriptors (feature vectors)
    SurfDescriptorExtractor extractor;
    
    Mat descriptors_object, descriptors_scene;
    
    extractor.compute( img_object, keypoints_object, descriptors_object );
    extractor.compute( img_scene, keypoints_scene, descriptors_scene );
    
    //-- Step 3: Matching descriptor vectors using FLANN matcher
    FlannBasedMatcher matcher;
    std::vector< DMatch > matches;
    matcher.match( descriptors_object, descriptors_scene, matches );
    
    double max_dist = 0; double min_dist = 100;
    
    //-- Quick calculation of max and min distances between keypoints
    for( int i = 0; i < descriptors_object.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 );
    
    //-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
    std::vector< DMatch > good_matches;
    
    for( int i = 0; i < descriptors_object.rows; i++ )
    { if( matches[i].distance < 3*min_dist )
      { good_matches.push_back( matches[i]); }
    }
    
    Mat img_matches;
    drawMatches( img_object, keypoints_object, img_scene, keypoints_scene,
                 good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
                 vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
    
    
    //-- Localize the object from img_1 in img_2
    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 );
    
    cvWaitKey(0);
    return 0;
    

    }

在 findHomography 中我有一个错误:“断言失败 (npoints >=0 && points2.Vector(2) == npoints)) in findHomography,文件 /modules/calib3d/src/fundam.cpp,第 1062 行”

怎么了? 我猜是有问题

keypoints.push_back(KeyPoint(keyPointLocation, 1));

非常感谢

【问题讨论】:

  • 你应该打电话给keypoints.push_back(KeyPoint(i,j));
  • 我有同样的错误,没关系 Point2f keyPointLocation(i, j); keypoints.push_back(KeyPoint(keyPointLocation, 1));或 keypoints.push_back(KeyPoint(i,j,1));

标签: c opencv detection


【解决方案1】:

首先你应该去抛出opencv documentationcv::KeyPoint 是一个存储由cv::FeatureDetector 对象检测到的点的结构。它包含关键点的坐标、有意义的邻域的直径、方向和响应。关键点的计算取决于检测器的定义(Sift,Surf,Mser,...)

开始here

【讨论】:

  • "它包含关键点的坐标、有意义的邻域的直径、方向和响应。" for(int i = 0; i
  • 大概是看不懂流程,cv::KeyPoint怎么写吧?
【解决方案2】:

如果您想手动创建KeyPoint's,这里有一个小示例可以帮助您入门:

vector<KeyPoint> keyPoints;
for(int i = 0; i < 10; i++)
{
    for(int j = 0; j < 10; j++)
    {
        Point2f keyPointLocation(i, j);
        float meaningfulNeighborhoodDiameter = 5.0;
        keyPoints.push_back(KeyPoint(keyPointLocation, meaningfulNeighborhoodDiameter));
    }
}

希望有帮助!

【讨论】:

  • 所以这个,几乎一样:keypoints.push_back(KeyPoint(i,j, 5.0); 我的函数仍然有错误,我将在我编辑的问题中显示文本
  • 没有。那是不一样的。 KeyPoint 采用 Point2f 对象而不是两个整数值。因此,您可以执行以下操作keyPoints.push_back(Point2f(i, j), 5.0);
猜你喜欢
  • 2014-02-10
  • 1970-01-01
  • 2012-11-12
  • 2014-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多