9

I am trying to rewrite the code described here. using the python API for Opencv.

The step 3 of the code has this lines:

 FlannBasedMatcher matcher;
 std::vector< DMatch > matches;
 matcher.match( descriptors_object, descriptors_scene, matches );

I have looked over and over in the OpenCV reference but found nothing related to a FlannBasedMatcher in python or some other object which can do the work.

Any ideas?

NOTE: I am usign OpenCV 2.3.1 and Python 2.6

Esteban Angee
  • 548
  • 1
  • 7
  • 19

3 Answers3

10

Looking in the examples provided by OpenCV 2.3.1 under the python2 folder, I found an implementation of a flann based match function which doesn't rely on the FlanBasedMatcher object.

Here is the code:

FLANN_INDEX_KDTREE = 1  # bug: flann enums are missing

flann_params = dict(algorithm = FLANN_INDEX_KDTREE,
                    trees = 4)

def match_flann(desc1, desc2, r_threshold = 0.6):
    flann = cv2.flann_Index(desc2, flann_params)
    idx2, dist = flann.knnSearch(desc1, 2, params = {}) # bug: need to provide empty dict
    mask = dist[:,0] / dist[:,1] < r_threshold
    idx1 = np.arange(len(desc1))
    pairs = np.int32( zip(idx1, idx2[:,0]) )
    return pairs[mask]
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
Esteban Angee
  • 548
  • 1
  • 7
  • 19
3

Pythonic FlannBasedMatcher is already available in OpenCV trunk, but if I remember correctly, it was added after 2.3.1 release.

Here is OpenCV sample using FlannBasedMatcher: http://code.opencv.org/projects/opencv/repository/revisions/master/entry/samples/python2/feature_homography.py

Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
  • Thanks for the quick answer. At this time, I need to stick to the 2.3.1 version so I will have to find my self another way to track features. – Esteban Angee Nov 29 '11 at 00:11
0

I could not post the dead link on the post above because of lack of reputations. So, I am posting it here.

The dead link(feature_homography.py)

AreUMine
  • 21
  • 4
  • Links are great, but it would be even more helpful if you could summarize a possible way to correct the problem outlined in the question. – Shanteshwar Inde Sep 10 '19 at 06:30