0
// 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);
}
정말 효과적입니다. 호출은'cv :: FlannBasedMatcher matcher = cv :: FlannBasedMatcher (cv :: makePtr (12, 20, 2)); ' –
또한, ORB 및 FLANN을 사용합니다 (다른 설명자와 함께 사용하는 경우도 있지만 현재는 발생하지 않음). 그런 다음 두 번째 인접 비율 테스트에서 보안 조건 인 if (matches [i] .size()> = 2)를 추가했습니다. –