2015-07-12 64 views
0

in this answer我理解了之前的所有內容「// 5.使用RANSAC驗證匹配項」。如何通過ORB獲得良好的Homography?

在我的代碼中,除了ransacTest的部分外,我使用該代碼。我面臨的問題是,我得到太多錯誤的「匹配」,並且/或者有時我的代碼找到的對象周圍的矩形太扭曲。

//Template image's corners 
obj_corners[0] = cvPoint(0, 0); 
obj_corners[1] = cvPoint(best_img.cols, 0); 
obj_corners[2] = cvPoint(best_img.cols, best_img.rows); 
obj_corners[3] = cvPoint(0, best_img.rows); 

obj.clear(); 
scene.clear(); 
for (int i = 0; i < best_matches.size(); i++) 
{ 
    //Get the keypoints from the good matches 
    obj.push_back(best_img_keypoints[ best_matches[i].queryIdx ].pt); // Template image 
    scene.push_back(frame_keypoints[ best_matches[i].trainIdx ].pt); // Frame 
} 

// -----Find homography----- // 
std::vector<uchar> outlier_mask; //I don't use this line 
cv::Mat H = findHomography(obj, scene, CV_RANSAC, reprojThres, outlier_mask); 
cv::perspectiveTransform(obj_corners, scene_corners, H); 

a)如果我使用基礎矩陣,我將能夠使用findHomography和perspectiveTransform?

b)上述行中是否有錯誤?

回答

0

我和你有同樣的問題。我通過將symMatches視爲good_matches(best_matches)和

if (good_matches.size() > 3){ 
    //-- Localize 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); 

    //-- Get the corners from the image_1 (the object to be "detected") 
    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); 

解決了這個問題,它也應該適合你。