OpenCV2.4 例程解析一 图像匹配

以下程序来自OpenCV自带的例程:

[cpp]   view plain copy
  1. #include "stdafx.h"  
  2. #include <stdio.h>  
  3. #include "opencv2/core/core.hpp"  
  4. #include "opencv2/features2d/features2d.hpp"  
  5. #include "opencv2/highgui/highgui.hpp"  
  6. #include "opencv2/nonfree/nonfree.hpp"  
  7.   
  8. using namespace cv;  
  9.   
  10. void help()  
  11. {  
  12.     printf("\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n"  
  13.         "Using the SURF desriptor:\n"  
  14.         "\n"  
  15.         "Usage:\n matcher_simple <image1> <image2>\n");  
  16. }  
  17.   
  18. int main(int argc, char** argv)  
  19. {  
  20.     //if(argc != 3)  
  21.     //{  
  22.     //  help();  
  23.     //  return -1;  
  24.     //}  
  25.   
  26.     Mat img1 = imread("H:\\OpenCV2.4\\opencv\\samples\\c\\box.png");//(argv[1], CV_LOAD_IMAGE_GRAYSCALE);  
  27.     Mat img2 = imread("H:\\OpenCV2.4\\opencv\\samples\\c\\box_in_scene.png");//(argv[2], CV_LOAD_IMAGE_GRAYSCALE);  
  28.     if(img1.empty() || img2.empty())  
  29.     {  
  30.         printf("Can't read one of the images\n");  
  31.         return -1;  
  32.     }  
  33.   
  34.     // detecting keypoints  
  35.     //检测关键点  
  36.     SurfFeatureDetector detector(400);  
  37.     vector<KeyPoint> keypoints1, keypoints2;  
  38.     detector.detect(img1, keypoints1);  
  39.     detector.detect(img2, keypoints2);  
  40.   
  41.     // computing descriptors  
  42.     // 计算描述器  
  43.     SurfDescriptorExtractor extractor;  
  44.     Mat descriptors1, descriptors2;  
  45.     extractor.compute(img1, keypoints1, descriptors1);  
  46.     extractor.compute(img2, keypoints2, descriptors2);  
  47.   
  48.     // matching descriptors  
  49.     //匹配描述器  
  50.     BFMatcher matcher(NORM_L2);  
  51.     vector<DMatch> matches;  
  52.     matcher.match(descriptors1, descriptors2, matches);  
  53.   
  54.     // drawing the results  
  55.     // 画结果  
  56.     namedWindow("matches", 1);  
  57.     Mat img_matches;  
  58.     drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);  
  59.     imshow("matches", img_matches);  
  60.     waitKey(0);  
  61.   
  62.     return 0;  
  63. }  

此例程比较简单不做深入解释。
转载自 http://blog.csdn.net/hjh2005/article/details/7610794


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值