Ask Your Question

How to use BRISK in OpenCV?

asked 2012-11-16 13:19:42 -0500

PAnikRus gravatar image

Hi! I can`t find any information of how to use BRISK key points detector and extractor in OpenCV on C/C++. If anybody knows, please, write the code or give a reference. Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-04-16 08:51:02 -0500

nickq gravatar image

updated 2013-04-16 09:54:08 -0500

Hi may be it can helpp

include header file where brisk class is implemented


//read some images in gray scale

   const char * PimA="box.png";   // object
   const char * PimB="box_in_scene.png"; // image

   cv::Mat GrayA =cv::imread(PimA);
   cv::Mat GrayB =cv::imread(PimB);
   std::vector<cv::KeyPoint> keypointsA, keypointsB;
   cv::Mat descriptorsA, descriptorsB;

//set brisk parameters

   int Threshl=60;
   int Octaves=4; (pyramid layer) from which the keypoint has been extracted
   float PatternScales=1.0f;

//declare a variable BRISKD of the type cv::BRISK

   cv::BRISK  BRISKD(Threshl,Octaves,PatternScales);//initialize algoritm

   BRISKD.detect(GrayA, keypointsA);
   BRISKD.compute(GrayA, keypointsA,descriptorsA);

   BRISKD.detect(GrayB, keypointsB);
   BRISKD.compute(GrayB, keypointsB,descriptorsB);

Declare one type off matcher

cv::BruteForceMatcher<cv::Hamming> matcher;

another match that can be use

///cv::FlannBasedMatcher matcher(new cv::flann::LshIndexParams(20,10,2));

std::vector<cv::DMatch> matches;
matcher.match(descriptorsA, descriptorsB, matches);

cv::Mat all_matches;
cv::drawMatches( GrayA, keypointsA, GrayB, keypointsB,
                     matches, all_matches, cv::Scalar::all(-1), cv::Scalar::all(-1),
                     vector<char>(),cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
cv::imshow( "BRISK All Matches", all_matches );

IplImage* outrecog = new IplImage(all_matches);
cvSaveImage( "BRISK All Matches.jpeg", outrecog );

you can also use: Common Interfaces of Feature Detectors

cv::Ptr<cv::FeatureDetector> detector = cv::Algorithm::create<cv::FeatureDetector>("Feature2D.BRISK");

detector->detect(GrayA, keypointsA);
detector->detect(GrayB, keypointsB);

cv::Ptr<cv::DescriptorExtractor> descriptorExtractor =cv::Algorithm::create<cv::DescriptorExtractor>("Feature2D.BRISK");

descriptorExtractor->compute(GrayA, keypointsA, descriptorsA);
descriptorExtractor->compute(GrayB, keypointsB, descriptorsB);

the result with this code is like at this

edit flag offensive delete link more



Or easier: cv::Ptr<cv::featuredetector>detector = cv::FeatureDetector::create("BRISK"); and cv::Ptr<cv::descriptorextractor>descriptorExtractor = cv::DescriptorExtractor::create("BRISK");

Guanta gravatar imageGuanta ( 2013-04-16 09:18:32 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2012-11-16 13:19:42 -0500

Seen: 6,346 times

Last updated: Apr 16 '13