2016-07-11 10 views
2

OpenCVで検出するためにORBを使って機能を抽出し、FLANNで一致させようとしています。本当に奇妙な結果が得られます。私の2枚の画像をロードし、グレースケールに変換した後、ここに私のコードです:C++ - ORBを使ったOpenCV機能の検出

// Initiate ORB detector 
    Ptr<FeatureDetector> detector = ORB::create(); 

// find the keypoints and descriptors with ORB 
    detector->detect(gray_image1, keypoints_object); 
    detector->detect(gray_image2, keypoints_scene); 

    Ptr<DescriptorExtractor> extractor = ORB::create(); 
    extractor->compute(gray_image1, keypoints_object, descriptors_object); 
    extractor->compute(gray_image2, keypoints_scene, descriptors_scene); 

// Flann needs the descriptors to be of type CV_32F 
    descriptors_scene.convertTo(descriptors_scene, CV_32F); 
    descriptors_object.convertTo(descriptors_object, CV_32F); 

    FlannBasedMatcher matcher; 
    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; 
    } 

    //-- Use only "good" matches (i.e. whose distance is less than 3*min_dist) 
    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]); 
     } 
    } 


    vector<Point2f> obj; 
    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); 
    } 

    // Find the Homography Matrix 
    Mat H = findHomography(obj, scene, CV_RANSAC); 
    // Use the Homography Matrix to warp the images 
    cv::Mat result; 
    warpPerspective(image1,result,H,Size(image1.cols+image2.cols,image1.rows)); 
    cv::Mat half(result,cv::Rect(0,0,image2.cols,image2.rows)); 
    image2.copyTo(half); 
    imshow("Result", result); 

そして、これは私が取得しています奇妙な結果のスクリーンショットです: screen shot

何が問題かもしれませんか?

ありがとうございます!

+0

マッチングが悪いと思われます。計算された変換は「非現実的」な結果につながります。 [example](http://docs.opencv.org/2.4/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html)で行われているように、試合を見てください – PhilLab

+0

私は全く同じことをやっていますが、いいえ?唯一の違いは、その例では使用できないSurfDescriptorExtractorを使用しているため、使用できないことです。 – YaronGh

+0

しかし、あなたは異なったイメージを使用しています - あなたのイメージがそのグッドと一致しないかもしれません。 '' imshow( "良い一致"、img_matches); ''(例を参照)であなたの試合を見てください – PhilLab

答えて

1

不適切な一致の結果が発生しています。データに適合するホモグラフィは「現実的」ではないため、画像が歪んでしまいます。

imshow("Good Matches", img_matches);と一致をデバッグするには、exampleのようにします。

あなたのマッチを改善するための複数のアプローチがあります。

  1. crossCheckオプションを使用し
  2. は完全に間違ってホモグラフィの計算
  3. を識別するためにcv::findHompgraphyでOutputArray maskを使用しSIFT ratio test
  4. を使用して... ...
0

ORBは、Flannで動作しないバイナリの特徴ベクトルです。代わりにブルートフォース(BFMatcher)を使用してください。

関連する問題