Pergunta

I have to implement a logo detection algoritm for android for my masterthesis. I'm currently using the openCV android library with NDK and have already managed to detect keypoints and setup descriptors for these keypoints using SURF.

Next step for me is to find 2 nearest matches for every keypoint using knnMatch, afterwards i'm throwing away the matches where the best knn match isn't very distinguishable compared with the second (the distance ration of these two is too low) here's a part of my code:

private static List<DMatch> knn(Mat queryDescriptors, Mat trainDescriptors) {
    List<List<DMatch>> matches = new ArrayList<List<DMatch>>();
    List<DMatch> retMatches = new ArrayList<DMatch>();
    DescriptorMatcher matcher = DescriptorMatcher
            .create(DescriptorMatcher.BRUTEFORCE);
    matcher.knnMatch(queryDescriptors, trainDescriptors, matches, 2);

My problem here is that when I have for example 500 descriptors for the query logo and 400 for the train logo, knn returns 500 matches, but every single one is for one and the same keypoint. Normally, it returns the 2 best matches for every descriptor, so 500 different descriptors, now they return 500 times the best matches for one and the same descriptor.

So when i draw these knn matches, there is 1 match line, drawn 500 times, between always the same keypoints

When I try the simple matcher, who simply returns the best match, I get more lines. I've tested this with comparing an image to itself. Knn return this one line, where a simple match draws all 500 matches, who are in this case ofcourse correct.

I can't find any posts where this similar issue has been treated, does any one had this problem or knows what i'm doing wrong here?

Thanx in advance.

Foi útil?

Solução

Next time you face a bug in OpenCV, please check if it's already submitted at OpenCV bug tracker and submit a new one if not found. What you faced is a bug in the JNI wrapper to C++ matcher, the fix has been just commited to OpenCV trunk. But you can make it locally in your copy of OpenCV-2.3.1, this is just one line of code:

  1. open org.opencv.utils.Converters::Mat_to_vector_vector_DMatch(Mat m, List> lldm) in OpenCV-2.3.1 Android library project (Converters.java)
  2. move the line List<DMatch> ldm = new ArrayList<DMatch>(); two lines down to make it the 1st line of the cycle for (Mat mi : mats)
  3. rebuild the OpenCV-2.3.1 project and your own in Eclipse
  4. make sure that now the matcher returns correct results
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top