【cv】使用opencv的FeatureDetector,DescriptorExtractor,DescriptorMatcher
来源:互联网 发布:淘宝店铺运营策划书 编辑:程序博客网 时间:2024/04/30 15:59
这个是能搜索到的比较全的解释。
http://blog.csdn.net/xiaowei_cqu/article/details/8652096
OpenCV官网:
http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html#featuredetector-create
"FAST" – FastFeatureDetector"STAR" – StarFeatureDetector"SIFT" – SIFT (nonfree module)"SURF" – SURF (nonfree module)"ORB" – ORB"BRISK" – BRISK"MSER" – MSER"GFTT" – GoodFeaturesToTrackDetector"HARRIS" – GoodFeaturesToTrackDetector with Harris detector enabled"Dense" – DenseFeatureDetector"SimpleBlob" – SimpleBlobDetector
可以看到 2.4.8中提供了11种Detector,多了一种 Brisk。其中 SIFT和SURF都是需要使用nonfree module的。可以使用第一篇博文中的代码,注意additional dependencies:
opencv_core248d.libopencv_highgui248d.libopencv_features2d248d.libopencv_imgproc248d.libopencv_nonfree248d.lib
为了方便大家,其实也包括自己啦,完整的代码可以如下:#include "stdafx.h"#include <iostream>#include <opencv2\opencv.hpp>#include "opencv2/highgui/highgui.hpp"#include "opencv\cv.h"#include <opencv2/nonfree/nonfree.hpp> #include <opencv2\nonfree\features2d.hpp>//#include "opencv2/features2d/features2d.hpp"//#include <iostream>//#include <stdio.h>//#include <stdlib.h>#include "opencv2/features2d/features2d.hpp"using namespace std;using namespace cv;int main(){initModule_nonfree();//if use SIFT or SURFPtr<FeatureDetector> detector = FeatureDetector::create( "SURF" );Ptr<DescriptorExtractor> descriptor_extractor = DescriptorExtractor::create( "SURF" );Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create( "BruteForce" );if( detector.empty() || descriptor_extractor.empty() )throw runtime_error("fail to create detector!");Mat img1 = imread("d:/image0001.jpg");Mat img2 = imread("d:/image0002.jpg");//detect keypoints;vector<KeyPoint> keypoints1,keypoints2;detector->detect( img1, keypoints1 );detector->detect( img2, keypoints2 );cout <<"img1:"<< keypoints1.size() << " points img2:" <<keypoints2.size() << " points" << endl << ">" << endl;//compute descriptors for keypoints;cout << "< Computing descriptors for keypoints from images..." << endl;Mat descriptors1,descriptors2;descriptor_extractor->compute( img1, keypoints1, descriptors1 );descriptor_extractor->compute( img2, keypoints2, descriptors2 );cout<<endl<<"Descriptors Size: "<<descriptors2.size()<<" >"<<endl;cout<<endl<<"Descriptor's Column: "<<descriptors2.cols<<endl<<"Descriptor's Row: "<<descriptors2.rows<<endl;cout << ">" << endl;//Draw And Match img1,img2 keypointsMat img_keypoints1,img_keypoints2;drawKeypoints(img1,keypoints1,img_keypoints1,Scalar::all(-1),0);drawKeypoints(img2,keypoints2,img_keypoints2,Scalar::all(-1),0);imshow("Box_in_scene keyPoints",img_keypoints1);imshow("Box keyPoints",img_keypoints2);descriptor_extractor->compute( img1, keypoints1, descriptors1 ); vector<DMatch> matches;descriptor_matcher->match( descriptors1, descriptors2, matches );Mat img_matches;drawMatches(img1,keypoints1,img2,keypoints2,matches,img_matches,Scalar::all(-1),CV_RGB(255,255,255),Mat(),4);imshow("Mathc",img_matches);waitKey(0);return 0;}
如果不想使用sift或者surf,下面这种就足够了。
#include "stdafx.h"#include <iostream>#include <opencv2/opencv.hpp>#include "opencv2/features2d/features2d.hpp"using namespace std;int main(){//read imagestring filename = "D:/image0001.jpg";cv::Mat img = cv::imread(filename, 0);//CV_Assert(!img.empty());//create detectorcv::Ptr<cv::FeatureDetector> detector;detector = cv::FeatureDetector::create("ORB");//detectcv::Mat output_img;vector<cv::KeyPoint> key_points;detector->detect(img, key_points);//showdrawKeypoints(img, key_points, output_img);cv::namedWindow("Image");cv::imshow("Image", output_img);cv::waitKey(0);return 0;}additional dependencies:
opencv_core248d.libopencv_highgui248d.libopencv_features2d248d.libopencv_imgproc248d.lib
0 0
- 【cv】使用opencv的FeatureDetector,DescriptorExtractor,DescriptorMatcher
- Opencv特征检测使用问题create is not a member of ‘cv::FeatureDetector {aka cv::Feature2D}’
- 使用OpenCV FeatureDetector报错的问题
- 【OpenCV】特征检测器 FeatureDetector
- 【OpenCV】特征检测器 FeatureDetector
- 【OpenCV】特征检测器 FeatureDetector
- opencv--feature2d之FeatureDetector
- 【OpenCV】特征检测器 FeatureDetector
- Opencv3中FeatureDetector未定义标识符,不在cv命名空间下的解决办法
- opencv 直方图 CV::calcHist使用
- OpenCV - "cv::Mat_"容器 的 使用 及 示例
- opencv中cv::GPU::ORB_GPU使用的问题
- opencv cv::Mat的用法
- opencv c++接口 cv::Mat使用
- C#下使用openCV(Emgu CV)
- cv::saturate_cast的使用
- RGBDSLAM 问题解决:create’ is not a member of ‘cv::FeatureDetector {aka cv::Feature2D}’ detecto
- rgb-d slam 问题解决:create’ is not a member of ‘cv::FeatureDetector {aka cv::Feature2D}’ detecto
- Java 开发 2.0: 现实世界中的 Redis
- CentOS 6.4 简单方法升级PHP到PHP 5.3.3
- Ubuntu12.04.3 配置nginx-rtmp支持HLS
- 云计算之现状
- iOS Crash文件分析
- 【cv】使用opencv的FeatureDetector,DescriptorExtractor,DescriptorMatcher
- python 多进程通信模块
- 虚拟化技术系列--openvswitch介绍
- Objective-C – 关联引用
- 1489 求二叉树的先序遍历 1291 数据结构上机测试4.1:二叉树的遍历与应用1【二叉树遍历顺序转换】
- Spring 3.0 注解注入详解
- Windows下利用c语言测试函数运行时间
- 信息产业联盟合作分类
- 【D3D9日记】圆球、圆柱中的Stack与Slices