2017-05-07 12 views
0

하였습니다.OpenCV의 - 사용 플란넬 ORB 기술자와 내가 무력보다 더 빠른 방법으로 기능 설명과 일치하는 플란넬를 사용하는 것을 시도하고있다 <p>OpenCV의 3.2</p>을 사용하고 기능

// 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가, 플란넬 우리가 그들을 변환해야하므로 형 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 

이 주장은 선 무슨 일 2277.

, opencv/modules/core/src/matrix.cpp 파일에?


코드 복제 문제.

#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

에서 촬영. 주석 값은 문서별로 권장되지만 경우에 따라 필요한 결과를 제공하지 않습니다. 다른 값 괜찮 았는데 : 아마 # 2

이 있음을 변환 할 수 있습니다

index_params = DICT (12 key_size = 12, # 20 multi_probe_level = 1 알고리즘 = FLANN_INDEX_LSH, 표 _ = 6, #)를 C++ API로?

+2

정말 효과적입니다. 호출은'cv :: FlannBasedMatcher matcher = cv :: FlannBasedMatcher (cv :: makePtr (12, 20, 2)); ' –

+1

또한, ORB 및 FLANN을 사용합니다 (다른 설명자와 함께 사용하는 경우도 있지만 현재는 발생하지 않음). 그런 다음 두 번째 인접 비율 테스트에서 보안 조건 인 if (matches [i] .size()> = 2)를 추가했습니다. –