这个是能搜索到的比较全的解释。
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
opencv_core248d.lib
opencv_highgui248d.lib
opencv_features2d248d.lib
opencv_imgproc248d.lib
opencv_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 SURF Ptr<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 keypoints Mat 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 image string filename = "D:/image0001.jpg"; cv::Mat img = cv::imread(filename, 0); //CV_Assert(!img.empty()); //create detector cv::Ptr<cv::FeatureDetector> detector; detector = cv::FeatureDetector::create("ORB"); //detect cv::Mat output_img; vector<cv::KeyPoint> key_points; detector->detect(img, key_points); //show drawKeypoints(img, key_points, output_img); cv::namedWindow("Image"); cv::imshow("Image", output_img); cv::waitKey(0); return 0; }additional dependencies:
opencv_core248d.lib opencv_highgui248d.lib opencv_features2d248d.lib opencv_imgproc248d.lib