0

I need to know specifically what the line for m, n in matches does to be able to implement it in C. matches is a matrix, but what values does m and n take and how do they move?

This is python code...

for m, n in matches:
    if m.distance < 0.75*n.distance:
        good.append([m])

NOTE In C++ matches is a std::vector<DMatch> and is an OpenCV program.

Thanks!

toonice
  • 2,211
  • 1
  • 13
  • 20
  • 2
    What is the complete type of `matches` in the C++ version? In Python, `for m,n in matches` suggests that `matches` is an iterable where each element is a tuple or list holding a pair of values that you are reading as `m` and `n` in the loop. So then in the C++ version, is `matches` of type `vector>`, `vector>`, or something else? – David Scarlett Jun 28 '17 at 00:20
  • SO question for [Multiple Assignment](https://stackoverflow.com/q/5182573/2823755). – wwii Jun 28 '17 at 00:29
  • I just illustrated this in https://stackoverflow.com/q/44771384 – hpaulj Jun 28 '17 at 01:09

2 Answers2

6

I'm guessing you are using the knnMatcher and following the tutorial at http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html

m and n are DMatch objects. Two objects are returned because k=2 at

matches = bf.knnMatch(des1,des2, k=2).

If you increase the value of k to 3, you will need

for m,n,p in matches:

to capture the results.

The CPP equivalent of knnmatch returns a vector of vectors of DMatch as is shown here

In fact, if you print out m.queryIdx, m.trainIdx, n.queryIdx, n.trainIdx you will see a pattern like 264 323 264 490indicating that the same index in the query image is matched against other indices in the training image.

Shawn Mathew
  • 2,198
  • 1
  • 14
  • 31
0

m and n are the values present at each iteration through matches. "How they move" depends on the type of matches and what kind of iteration it provides. If it's a list of tuples, then they will each move straight down the list, element by element.

Alex
  • 780
  • 4
  • 12