10

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

PS:以及如何在 OpenCV 2.4.3 中使用它?

4

1 回答 1

22

在 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

于 2012-12-12T02:52:46.533 回答