码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV入门 - 关键点描述子匹配Brute-force

时间:2015-05-12 15:36:14      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:opencv   bfmatcher   

OpenCV入门 - 关键点描述子匹配Brute-force


对图片提取特征向量之后进行keypoint descriptors matching,从而可以判断特定图像与训练集中图片的匹配程度,BFMatcher暴力匹配类继承自抽象类DescriptorMatcher,"Brute-force descriptor matcher. For each descriptor in the first set, this matcher finds the closest descriptor in the second set by trying each one. This descriptor matcher supports masking permissible matches of descriptor sets",下面通过一个简单实例可以看到效果。
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> //


#include <iostream>
using namespace cv;
using namespace std;


int main(int argc, const char *argv[]){
    Mat car1 = imread("car1.jpeg", 0);// load as grayscale
    Mat car2 = imread("car2.jpeg", 0);


    SiftFeatureDetector detector;
    vector<KeyPoint> keypoints1, keypoints2;
    detector.detect(car1, keypoints1);
    detector.detect(car2, keypoints2);
    cout << "# keypoints of car1 :" << keypoints1.size() << endl;
    cout << "# keypoints of car2 :" << keypoints2.size() << endl;
   
    Mat descriptors1,descriptors2;
    Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("SIFT");
    extractor->compute(car1,keypoints1,descriptors1);
    extractor->compute(car2,keypoints2,descriptors2);
    
    BFMatcher bfmatcher(NORM_L2, true);
    vector<DMatch> matches;
    bfmatcher.match(descriptors1, descriptors2, matches);
    cout << "# matches : " << matches.size() << endl;


    // show it on an image
    Mat output;
    drawMatches(car1, keypoints1, car2, keypoints2, matches, output);
    imshow("car matches result",output);
    waitKey(0);


    return 0;
}

运行结果:
技术分享


参考:
1.cv::imread()
2.Drawing Function of Keypoints and Matches
3.BFMatcher




OpenCV入门 - 关键点描述子匹配Brute-force

标签:opencv   bfmatcher   

原文地址:http://blog.csdn.net/vonzhoufz/article/details/45669993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!