1

我想在一些场景图像上找到模板图像。所以我尝试Homography在场景图像和模板图像之间找到。我正在使用OpenCVc++。首先SURF用于查找图像和模板的描述符。然后使用FlannBasedMatcher获取匹配点。一切似乎都很好,但是当我只为每个图像单独运行该程序时,结果与我为所有场景图像运行它时不同。

Ptr<FlannBasedMatcher> matcher = FlannBasedMatcher::create();
vector<DMatch> matches;
matcher->match(objectDescriptor, sceneDescriptor, matches);
double max_dist = 0, min_dist = DBL_MAX;

for (int i = 0; i < objectDescriptor.rows; i++)
{
    double dist = matches[i].distance;
    if (dist < min_dist) min_dist = dist;
    if (dist > max_dist) max_dist = dist;
}

vector< DMatch > goodMatches;
for (int i = 0; i < objectDescriptor.rows; i++)
{
    if (matches[i].distance < max((coeffGoodMatches * min_dist), maxDistanceMatches))
    {
        goodMatches.push_back(matches[i]);
    }
}

vector<Point2f> obj;
vector<Point2f> scene;
for (int i = 0; i < goodMatches.size(); i++)
{
    //-- Get the keypoints from the good matches
    obj.push_back(keypoints_object[goodMatches[i].queryIdx].pt);
    scene.push_back(keypoints_scene[goodMatches[i].trainIdx].pt);
}
Mat H = findHomography(obj, scene, CV_RANSAC);

Mat result;
warpPerspective(img_scene, result, H, img_object.size(), WARP_INVERSE_MAP);

SURF每个场景找到的关键点和描述符都是相同的,但是当FlannBasedMatcher尝试匹配描述符时,结果是不同的。我也尝试FlannBasedMatcher像下面一样清除,但结果是一样的,没有清除。

matcher->clear();

任何想法?

4

0 回答 0