10

I want to try the new class FREAK in OpenCV 2.4.2.

I tried to use common interface of feature detector to construct FREAK, but,of course, it doesn't work. How should I revise my code to get result?

#include <stdio.h>
#include <iostream>
#include <opencv\cxcore.h>
#include <opencv2\nonfree\features2d.hpp>
#include <opencv\highgui.h>
#include <opencv2\features2d\features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;

int main(){
    Mat mat1;
    mat1 = imread("Testimg06.jpg",0);
    vector<KeyPoint> P1;
    Ptr<FeatureDetector> freakdes;
    Ptr<DescriptorExtractor> descriptorExtractor; 
    freakdes = FeatureDetector::create("FREAK"); 

    freakdes->detect(mat1,P1);

    Mat keypoint_img;

    drawKeypoints( mat1, P1, keypoint_img, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
     imshow("Keypoints 1", keypoint_img );
    cvWaitKey(0);

}
ArtemStorozhuk
  • 8,715
  • 4
  • 35
  • 53
Jason C
  • 127
  • 2
  • 10

2 Answers2

8

FREAK is descriptor only. There is no corresponding feature detector.

So you need to combine it with one of the available detectors: FAST, ORB, SIFT, SURF, MSER or use goodFeaturesToTrack function.

Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
  • Thanks a lot! Dose that mean i should use `DescriptorExtractor` to set FREAK as descriptor of feature? – Jason C Oct 16 '12 at 02:57
7

There is an OpenCV example that shows how to use FREAK combined with FAST.

The basic instructions are:

FREAK extractor;
BruteForceMatcher<Hamming> matcher;
std::vector<KeyPoint> keypointsA, keypointsB;
Mat descriptorsA, descriptorsB;
std::vector<DMatch> matches;

FAST(imgA,keypointsA,10);
FAST(imgB,keypointsB,10);

extractor.compute( imgA, keypointsA, descriptorsA );
extractor.compute( imgB, keypointsB, descriptorsB );

matcher.match(descriptorsA, descriptorsB, matches);
Mar de Romos
  • 719
  • 2
  • 9
  • 22
  • 1
    Bear in mind that, to have best performance, FREAK needs rotation and scale invariant keypoints, so FAST is not the best option, see *EVALUATION OF BINARY KEYPOINT DESCRIPTORS* for more info: http://2013.ieeeicip.org/proc/pdfs/0003652.pdf – aledalgrande Oct 24 '14 at 17:36