[OpenCV] BRIEF에는 FLANN을 사용할 수 없다.

학술 2011. 9. 15. 11:33 Posted by 양고
FLANN은 SURF와 같은 4-byte floating point 기반 descriptor에서만 사용할 수 있다.
BRIEF는 (바이트 단위로 재구성된) 바이너리 스트링이기 때문에 FLANN을 사용하는 것은 어려울 듯.
ㅠㅠ

해결 방안은
1. SURF로 해본다. --> 일단은 이쪽으로 MH를 실험.
2. 다른 ANN 라이브러리를 찾는다.


http://opencv-users.1802565.n2.nabble.com/FLANN-help-td6185055.html
FLANN works with 4 bytes descriptors because needs to calculate distances and then uses floating point values.

Try to take a look at original FLANN documentation at FLANN site, but I'm pretty sure about it.

Walter

-----
Walter Lucetti
http://www.robot-home.it
-----
Inviato da Samsung Galaxy Tab
"huck.wach" <[hidden email]> ha scritto:>I can make it work using SURF descriptors rather than BRIEF descriptors.  And the only difference I can tell is that BRIEF uses  1 byte descriptors and SURF uses 4 byte.  It seems like FLANN is expecting the 4 byte ones.  I suppose I can convert the brief ones to 4 byte but that seems not the best option.  Is there a way to ask FLANN to work with the 1 byte descriptors of BRIEF?

>
>--- In [hidden email], "huck.wach" <huck.wach@...> wrote:
>>
>> I'm trying to follow the example in the two samples descriptor_extractor_matcher and matching_to_many_images.  But I keep having runtime errors.  In one attempt I try this...
>>
>> cv::FlannBasedMatcher matcher;
>> matcher.match( desc[0], desc[1], matches );


https://code.ros.org/trac/opencv/ticket/978

Ticket #978 (reopened enhancement)

Opened 6 months ago

Last modified 6 weeks ago

Crash when using BruteForce-Hamming or BruteForce-HammingLUT descriptor matchers

Reported by: tijszwinkels Owned by: mdim
Priority: minor Component: samples
Version: SVN (trunk) Keywords: descriptor matcher compatibility
Cc: yvonnic2m@…

Description

This crash can easily be reproduced with the matching_to_many_images sample program.

Both:

matching_to_many_images SURF SURF BruteForce?-Hamming foo.jpg foo.txt foodir

and

matching_to_many_images SURF SURF BruteForce?-HammingLUT foo.jpg foo.txt foodir

fail with the following error:

OpenCV Error: Assertion failed (DataType?<ValueType?>::type == queryDescriptors.type()) in commonKnnMatchImpl, file /home/tijs/src/OpenCV-svn/opencv/opencv/modules/features2d/include/opencv2/features2d/features2d.hpp, line 2132
terminate called after throwing an instance of 'cv::Exception'

what(): /home/tijs/src/OpenCV-svn/opencv/opencv/modules/features2d/include/opencv2/features2d/features2d.hpp:2132: error: (-215) DataType?<ValueType?>::type == queryDescriptors.type() in function commonKnnMatchImpl

Aborted

OpenCV version: Latest SVN (trunk@4844)
Kernel 2.6.32 x86_64
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
Built with: SSE2 SSE3 SSSE3 TBB and CUDA among others.

Change History

Changed 5 months ago by mdim

  • status changed from new to closed
  • resolution set to fixed

This is not a bug. You can not match SURF descriptors by Hamming or HammingLUT distances. These distances are used for matching the bit strings stored as uchar vectors only, but SURF descriptor is a float vector (is not binary descriptor). So, BruteForceMatcher? throws the exception you got.

SURF descriptors can be matched by L2 or L1 distances. Hamming or HammingLUT distances are used to match eg. BRIEF descriptors.

Changed 7 weeks ago by yvo2m

  • status changed from closed to reopened
  • cc yvonnic2m@… added
  • type changed from defect to enhancement
  • component changed from features2d to samples
  • keywords descriptor matcher compatibility added; sample crash removed
  • resolution fixed deleted

Maybe a note should be printed on screen when you launch the executable without any arguments, telling which are the different detectors, descriptors and the matching method working with them.
Something like :

  • Detectors:
    • FAST
    • STAR
    • SIFT
    • SURF
    • ORB
    • MSER
    • GFTT
    • HARRIS
    • Grid{Detector}
    • Pyramid{Detector}
    • Dynamic{Detector}
  • Descriptors:
    • float descriptors:
      • SIFT
      • SURF
    • uchar descriptors:
      • ORB
      • BRIEF
  • Matchers:
    • for float descriptor:
      • FlannBased
      • BruteForce
      • BruteForce-L1
    • for uchar descriptor:
      • BruteForce-Hamming
      • BruteForce-HammingLUT

Changed 6 weeks ago by andrey.kamaev

I think that classification from previous post has to be included into features2d reference manual.

And one addition:
If I not mistaken, FlannBasedMatcher? is also able to match uchar descriptors, when it is created with custom parameters.

Changed 6 weeks ago by yvo2m

Adding classification in manual is not sufficient because OpenCV samples have to be easy to use.

And for your addition:
Yes but I think that uchar descriptor of ORB and BRIEF means bit descriptor and not Bytes (each bit has to be compared separately; XOR and sum bits).

Changed 6 weeks ago by andrey.kamaev

Just checked source code - if flann algorithm is set to FLANN_INDEX_LSH then Hamming distance is used. So it should be applicable for ORB and BRIEF.

Changed 6 weeks ago by yvo2m

So the sample !matching_to_many_images should be modified to accept Hamming distance based FLANN.

thanks for the precision !

Changed 6 weeks ago by yvo2m

Well, in fact FLANN_INDEX_LSH is not available in OpenCV 2.3 as it has been integrated in OpenCV trunk in commit 6034 the 07/14 with the integration on FLANN 1.6