opencv 3/C++FLANN 특징 일치 방식
함수 detectAndCompute()매개 변수 설명:
void detectAndCompute(
InputArray image, //
InputArray mask, //
CV_OUT std::vector<KeyPoint>& keypoints,//
OutputArray descriptors,// (descriptors[i] keypoints[i] )
bool useProvidedKeypoints=false //
);
match()는 검색 에서 모든 설명자 의 가장 좋 은 일치 성 을 찾 습 니 다.매개 변수 설명:
void match(
InputArray queryDescriptors, //
InputArray trainDescriptors, //
CV_OUT std::vector<DMatch>& matches, //
InputArray mask=noArray() //
) const;
FLANN 특징 일치 예시:
#include<opencv2/opencv.hpp>
#include<opencv2/xfeatures2d.hpp>
using namespace cv;
using namespace cv::xfeatures2d;
//FLANN
int main()
{
Mat src1,src2;
src1 = imread("E:/image/image/card2.jpg");
src2 = imread("E:/image/image/cards.jpg");
if (src1.empty() || src2.empty())
{
printf("can ont load images....
");
return -1;
}
imshow("image1", src1);
imshow("image2", src2);
int minHessian = 400;
// SURF
Ptr<SURF>detector = SURF::create(minHessian);
std::vector<KeyPoint>keypoints1;
std::vector<KeyPoint>keypoints2;
Mat descriptor1, descriptor2;
//
detector->detectAndCompute(src1, Mat(), keypoints1, descriptor1);
detector->detectAndCompute(src2, Mat(), keypoints2, descriptor2);
// Flann
FlannBasedMatcher matcher;
std::vector<DMatch>matches;
//
matcher.match(descriptor1, descriptor2, matches);
double minDist = 1000;
double maxDist = 0;
for (int i = 0; i < descriptor1.rows; i++)
{
double dist = matches[i].distance;
printf("%f
", dist);
if (dist > maxDist)
{
maxDist = dist;
}
if (dist < minDist)
{
minDist = dist;
}
}
//DMatch
std::vector<DMatch>goodMatches;
for (int i = 0; i < descriptor1.rows; i++)
{
double dist = matches[i].distance;
if (dist < max(2.5*minDist, 0.02))
{
goodMatches.push_back(matches[i]);
}
}
Mat matchesImg;
drawMatches(src1, keypoints1, src2, keypoints2, goodMatches, matchesImg, Scalar::all(-1), Scalar::all(-1), std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
imshow("output", matchesImg);
waitKey();
return 0;
}
이상 의 opencv 3/C++FLANN 특징 매 칭 방식 은 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 께 참고 가 되 고 저희 도 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.