opencv2.4.3特征提取的实现表示方法

本文介绍了如何在OpenCV 2.4.3中使用自定义类实现特征提取,特别是BRISK算法。首先,需要包含'opencv2/features2d/features2d.hpp'头文件,然后读取灰度图像并设置BRISK参数。接着,声明一个cv::BRISK类型的变量,并实例化BRISK检测器。最后,可以使用不同的匹配器进行特征匹配。
摘要由CSDN通过智能技术生成

1.采用自定义的类实现形式

Another way to get brisk in OpenCV 2.4.3

include header file "opencv2/features2d/features2d.hpp" 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.create("Feature2D.BRISK");

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

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

2.采用通用接口
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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值