2017-05-07 11 views
0

と一致するように、私は力ずくよりも高速な方法で機能記述子を一致させるためにFLANNを使用しようとしていますOpenCVの3.2OpenCVの - 利用FLANN ORB記述子を持つ機能

を使用しています。

// Ratio to the second neighbor to consider a good match. 
#define RATIO 0.75 

void matchFeatures(const cv::Mat &query, const cv::Mat &target, 
        std::vector<cv::DMatch> &goodMatches) { 
    std::vector<std::vector<cv::DMatch>> matches; 
    cv::Ptr<cv::FlannBasedMatcher> matcher = cv::FlannBasedMatcher::create(); 
    // Find 2 best matches for each descriptor to make later the second neighbor test. 
    matcher->knnMatch(query, target, matches, 2); 
    // Second neighbor ratio test. 
    for (unsigned int i = 0; i < matches.size(); ++i) { 
     if (matches[i][0].distance < matches[i][1].distance * RATIO) 
      goodMatches.push_back(matches[i][0]); 
    } 
} 

このコードでは、SURFおよびSIFT記述子で私はうまく動作しますが、ORBでは動作しません。

OpenCV Error: Unsupported format or combination of formats (type=0) in buildIndex 

それはhereを言われていますと、FLANNので、我々はそれらを変換する必要があるタイプCV_32Fであることが記述子を必要とします。

if (query.type() != CV_32F) query.convertTo(query, CV_32F); 
if (target.type() != CV_32F) target.convertTo(target, CV_32F); 

ただし、この修正により、convertToの別のエラーが返されます。

OpenCV Error: Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in create 

このアサーションは何が起こっているopencv/modules/core/src/matrix.cppファイル、行2277.

にありますか?


問題を複製するコード。

#include <opencv2/opencv.hpp> 

int main(int argc, char **argv) { 
    // Read both images. 
    cv::Mat image1 = cv::imread(argv[1], cv::IMREAD_GRAYSCALE); 
    if (image1.empty()) { 
     std::cerr << "Couldn't read image in " << argv[1] << std::endl; 
     return 1; 
    } 
    cv::Mat image2 = cv::imread(argv[2], cv::IMREAD_GRAYSCALE); 
    if (image2.empty()) { 
     std::cerr << "Couldn't read image in " << argv[2] << std::endl; 
     return 1; 
    } 
    // Detect the keyPoints and compute its descriptors using ORB Detector. 
    std::vector<cv::KeyPoint> keyPoints1, keyPoints2; 
    cv::Mat descriptors1, descriptors2; 
    cv::Ptr<cv::ORB> detector = cv::ORB::create(); 
    detector->detectAndCompute(image1, cv::Mat(), keyPoints1, descriptors1); 
    detector->detectAndCompute(image2, cv::Mat(), keyPoints2, descriptors2); 
    // Match features. 
    std::vector<cv::DMatch> matches; 
    matchFeatures(descriptors1, descriptors2, matches); 
    // Draw matches. 
    cv::Mat image_matches; 
    cv::drawMatches(image1, keyPoints1, image2, keyPoints2, matches, image_matches); 
    cv::imshow("Matches", image_matches); 
} 

答えて

1

FLANNパラメータを調整しましたか?

は、ORBを使用している間、あなたは以下を渡すことができhttp://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html

から撮影します。コメントされた値はドキュメントごとに推奨されますが、場合によっては必要な結果が得られませんでした。他の値はうまく働いた。:

INDEX_PARAMS = dictの(アルゴリズム= FLANN_INDEX_LSH、 table_number = 6、#12 KEY_SIZE = 12、#20 multi_probe_level = 1)#2

をおそらくあなたがいることを変換することができますC + +のAPIに?

+2

本当に処理されました。この呼び出しは 'cv :: FlannBasedMatcher matcher = cv :: FlannBasedMatcher(cv :: makePtr (12,20,2));' –

+1

でした。 ORBとFLANNを使用しています(おそらく他の記述子でもこれが起こりますが、現在はそうではありません)。次に、第2の隣接比テストでは、セキュリティ条件 'if(matches [i] .size()> = 2)'を追加しました。 –

関連する問題