Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize FLANN feature matching with opencv3/C++

Shulou Source: shulou.com Published: 2022-05-31 21:54:15 09月21日 Update

This article mainly introduces opencv3/C++ how to achieve FLANN feature matching related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this opencv3/C++ how to achieve FLANN feature matching article will have a harvest, let's take a look.

Use the function detectAndCompute () to detect key points and calculate descriptors

The function detectAndCompute () argument states:

Void detectAndCompute (InputArray image, / / Image InputArray mask, / / Mask CV_OUT std::vector& keypoints,// set of output key points OutputArray descriptors,// calculation descriptor (descriptors [I] is a calculation descriptor for keypoints [I]) bool useProvidedKeypoints=false / / use key points)

Match () looks for the best match for each descriptor from the query set.

Parameter description:

Void match (InputArray queryDescriptors, / / query descriptor set InputArray trainDescriptors, / / training descriptor collection CV_OUT std::vector& matches, / / match InputArray mask=noArray () / / specify the allowed matching mask between the input query and the list matrix of descriptors) const

Example of FLANN feature matching:

# include#includeusing namespace cv;using namespace cv::xfeatures2d;//FLANN is faster for high-dimensional data 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....\ n"); return-1;} imshow ("image1", src1) Imshow ("image2", src2); int minHessian = 400; / Select SURF feature Ptrdetector = SURF::create (minHessian); std::vectorkeypoints1; std::vectorkeypoints2; Mat descriptor1, descriptor2; / / detect key points and calculate descriptors detector- > detectAndCompute (src1, Mat (), keypoints1, descriptor1); detector- > detectAndCompute (src2, Mat (), keypoints2, descriptor2); / / Flann-based descriptor matcher FlannBasedMatcher matcher; std::vectormatches / / find the best match for each descriptor from the query set 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 \n", dist); if (dist >

MaxDist) {maxDist = dist;} if (dist

< minDist) { minDist = dist; } } //DMatch类用于匹配关键点描述符的 std::vectorgoodMatches; 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(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); imshow("output", matchesImg); waitKey(); return 0;}

This is the end of the article on "how to achieve FLANN feature matching in opencv3/C++". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve FLANN feature matching in opencv3/C++". If you want to learn more knowledge, welcome to follow the industry information channel.

Tags: Features keys key points queries knowledge content functions parameters articles detection between values images easy to operate data articles easy to understand more look matrix Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei Redmi Shulou Tech Info MariaDB