# Equivalent of matchFeatures() Matlab in OpenCV (C++)

**URL:** <https://forum.opencv.org/t/equivalent-of-matchfeatures-matlab-in-opencv-c/5599>\
**Category:** C++\
**Tags:** features2d\
**Created:** [October 12, 2021, 7:00pm UTC](https://forum.opencv.org/t/equivalent-of-matchfeatures-matlab-in-opencv-c/5599 "2021-10-12T19:00:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elektron97](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/elektron97/32/3423_2.png) [@Elektron97](https://forum.opencv.org/u/Elektron97)\
**Post date:** [October 12, 2021, 7:00pm UTC](https://forum.opencv.org/t/equivalent-of-matchfeatures-matlab-in-opencv-c/5599/1 "2021-10-12T19:00:06Z")

</div>

Hi everyone! I’m working on my Visual Odometry project. I’m using SURF detector and BRUTEFORCE matching in this way:

```auto

//-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors`
Ptr<SURF> detector = SURF::create( minHessian );`
vector<KeyPoint> keypoints1, keypoints2;`
Mat descriptors1, descriptors2;`
detector->detectAndCompute( img1, noArray(), keypoints1, descriptors1 );`
detector->detectAndCompute( img2, noArray(), keypoints2, descriptors2 );`
//-- Step 2: Matching descriptor vectors with a brute force matcher`
// Since SURF is a floating-point descriptor NORM_L2 is used`
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);`
vector< DMatch > matches;`
matcher->match( descriptors1, descriptors2, matches);`

```

But my result is different from matchFeatures() of MATLAB. In particular, the size of matches is equal to the size of keypoints1, meanwhile in MATLAB, it’s a different size.

After, for matching and converting Keypoints in v `ector<Point2f>` i’m using this loop:

`// Convert keypoints into Point2f (Solo i KP matchati)`  
`vector<Point2f> keypoints1_conv, keypoints2_conv;`  
`for (vector<DMatch>::const_iterator it= kp_match.match.begin(); it!= kp_match.match.end(); ++it)`  
`{`  
`// Get the position of keypoints1`  
`keypoints1_conv.push_back(kp_match.Kpoints1[it->queryIdx].pt); //query per keypoints1`  
`// Get the position of keypoints2`  
`keypoints2_conv.push_back(kp_match.Kpoints2[it->trainIdx].pt); //train per keypoints2`  
`}`

I tried also with knnMatch and radiusMatch, but with similar results.

---

<div class="post-metadata">

**Author:** ![Elektron97](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/elektron97/32/3423_2.png) [@Elektron97](https://forum.opencv.org/u/Elektron97)\
**Post date:** [October 17, 2021, 5:27pm UTC](https://forum.opencv.org/t/equivalent-of-matchfeatures-matlab-in-opencv-c/5599/3 "2021-10-17T17:27:35Z")

</div>

I found solution on this [tutorial](https://docs.opencv.org/3.4/d5/d6f/tutorial_feature_flann_matcher.html).
