How to apply my own Distance Metric in BFMatcher

asked 2014-09-24 05:25:26 -0600

Sulman Baig gravatar image

I am trying to implement Jensen-Bregman LogDet Divergence which is distance measurable between two covariance matrices. My implementation is to match SURF Features on basis of JBLD.

So my question is how I can implement JBLD distance measurement for BFMatcher now I am using NORM_L2 method.

You can see the source codes and paper on JBLD on gitHub Repo.

edit retag flag offensive close merge delete

Comments

2

In the early OpenCV versions ( < 2.4?) it was very easy possible. Unfortunately, with the refactoring from BruteForceMatcher to BFMatcher (whyever this was neccessary) this isn't that easy anymore in the sense that you really have to dig into OpenCV's code and add this distance by hand.

The paper looks very interesting and I am exciting to test it when you are finished.

Guanta gravatar imageGuanta ( 2014-09-24 06:01:22 -0600 )edit

Thanks Guanta... Is there any other way to implement covariance distance measuring in any application like tracking cars, face recognition, texture recognition etc. I just want to implement JBLD and compare it distance measurement with others like AIRM, LERM etc.

Also any Matcher like Flann that could still employ Distance measurement?

Sulman Baig gravatar imageSulman Baig ( 2014-09-24 07:11:44 -0600 )edit

Also Guanta can you help me where to exactly change opencv code to employ this technique?

Sulman Baig gravatar imageSulman Baig ( 2014-09-24 07:13:00 -0600 )edit
2

For opencv: add the norm to the others in /modules/features2d/include/opencv2/features2d.hpp and adjust modules/features2d/src/matchers.cpp (look for distType or normType). Guess actually only these two files - so maybe not too difficult at all?

For flann (the author's version not the one in OpenCV) you have to edit afaik: src/cpp/flann/define.h , src/cpp/flann/flann.cpp and src/cpp/flann/algorithms/dist.h .

If you neither want to use BFMatcher nor flann you can of course write your own bruteforce matcher - which isn't very difficult (two for loops in which you compare each descriptor with each other using JBLD) if you don't need a fast optimized version.

Good luck! And let me know if you are successful and get good results (just leave a comment here).

Guanta gravatar imageGuanta ( 2014-09-24 13:41:27 -0600 )edit

Thanks Guanta for such a detailed reply. Can you help me how I can match two descriptors? Which information from descriptors is useful for me to find match and corresponding keypoint which has been matched? If there is some code available or some tutorial for matcher that would be very very helpful for me to understand.

Sulman Baig gravatar imageSulman Baig ( 2014-09-25 07:27:35 -0600 )edit
2

Maybe I don't get your question right, but basically a match gives you a score which is dependent on the norm of two descriptors. Example if you have a two-dimensional descriptor (=feature vector) x and another y, then using the L2 norm, their distance would be d = sqrt( (x_1-y_1)^2+(x_2-y_2) ). According to this distance / score you continue, e.g. using the best match, which would be the same as BFMatcher w. k=1 or whatever.

Guanta gravatar imageGuanta ( 2014-09-25 10:14:03 -0600 )edit
2

maybe you could add a link to the original paper ?

(github does not play nice with binary content)

berak gravatar imageberak ( 2014-09-26 09:12:31 -0600 )edit