如何在OpenCV中使用BRISK?

时间:2012-11-16 20:23:46

标签: algorithm opencv

我无法在C / C ++上找到有关如何在OpenCV中使用BRISK关键点检测器和提取器的任何信息。如果有人知道,请写下代码或提供参考。谢谢!

P.S。:如何在OpenCV 2.4.3中使用它?

1 个答案:

答案 0 :(得分:21)

另一种在OpenCV 2.4.3中获得活力的方法

包含头文件“opencv2 / features2d / features2d.hpp”,其中实现了快速类

//以灰度读取一些图像

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;

//设置轻快的参数

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

//声明一个cv :: BRISK

类型的变量BRISKD
cv::BRISK  BRISKD(Threshl,Octaves,PatternScales);//initialize algoritm
BRISKD.create("Feature2D.BRISK");

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

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

从匹配器中声明一种类型

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

可以使用的另一场比赛

//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 );
    cv::waitKey(0);

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

您还可以使用:特征检测器的通用接口

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);

此代码的结果就像这样 http://docs.opencv.org/_images/Feature_Description_BruteForce_Result.jpg