Opencv providesFeaturedetectorFeature Detection and matching
class CV_EXPORTS FeatureDetector{public:virtual ~FeatureDetector();void detect( const Mat& image, vector<KeyPoint>& keypoints,const Mat& mask=Mat() ) const;void detect( const vector<Mat>& images,vector<vector<KeyPoint> >& keypoints,const vector<Mat>& masks=vector<Mat>() ) const;virtual void read(const FileNode&);virtual void write(FileStorage&) const;static Ptr<FeatureDetector> create( const string& detectorType );protected:...};
Featuredetetor is a virtual class. You can use multiple Feature Detection Methods to define featuredetector objects. Use the CREATE () function to call:
Ptr<FeatureDetector> FeatureDetector::create(const string& detectorType);
Opencv 2.4.3 provides 10 Feature Detection Methods:
- "Fast"-fastfeaturedetector
- "Star"-starfeaturedetector
- "Sift"-sift (nonfree module)
- "Surf"-surf (nonfree module)
- "ORB"-ORB
- "Mser"-mser
- "Gftt"-goodfeaturestotrackdetector
- "Harris"-goodfeaturestotrackdetector with Harris detector Enabled
- "Dense"-densefeaturedetector
- "Simpleblob"-simpleblobdetector
Features in images can be divided into three types: Point features, line features, and block features. The fast algorithm is a fast extraction of Point features proposed by Rosten [1]. Harris and gftt are also point features, more specifically corner features (refer to here ). Simpleblob is a simple block feature that can be set
SimpleblobdetectorThe parameter determines the main properties of the image block, providing 5 types: color by color, Area
By area, circular degree by circularity, maximum inertia (do not know how to translate) and minimum inertia ratio by ratio of the minimum inertia to maximum inertia, and convex by convexity. the most common feature is sift, And the scale-unchanged Feature Matching Algorithm (see here); and the developed surf can all be seen as more complex block features. The two algorithms are included in the module of opencv nonfree. You need to add opencv_nonfree243.lib in the reference item of the attachment, and add the following to the Code:
initModule_nonfree();
As for other algorithms, I don't know much about pai_^, a simple demonstration:
int main(){initModule_nonfree();//if use SIFT or SURFPtr<FeatureDetector> detector = FeatureDetector::create( "SIFT" );Ptr<DescriptorExtractor> descriptor_extractor = DescriptorExtractor::create( "SIFT" );Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create( "BruteForce" );if( detector.empty() || descriptor_extractor.empty() )throw runtime_error("fail to create detector!");Mat img1 = imread("images\\box_in_scene.png");Mat img2 = imread("images\\box.png");//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(10000);return 0;}
Feature Detection Result box_in_scenebox feature point matching result: Another point to be mentioned in match is that simpleblob has a bug. Instead of calling the PTR <featuredetector> detector = featuredetector: Create ("simpleblob"); statement, you must createSimpleblobdetectorObject:
Mat image = imread("images\\features.jpg");Mat descriptors;vector<KeyPoint> keypoints;SimpleBlobDetector::Params params;//params.minThreshold = 10;//params.maxThreshold = 100;//params.thresholdStep = 10;//params.minArea = 10; //params.minConvexity = 0.3;//params.minInertiaRatio = 0.01;//params.maxArea = 8000;//params.maxConvexity = 10;//params.filterByColor = false;//params.filterByCircularity = false;SimpleBlobDetector blobDetector( params );blobDetector.create("SimpleBlob");blobDetector.detect( image, keypoints );drawKeypoints(image, keypoints, image, Scalar(255,0,0));
The following are image features detected by color by simpleblobdetector:
[1] Rosten. Machine Learning for high-speed corner detection, 2006
(Reprinted please indicate the author and Source: http://blog.csdn.net/xiaowei_cqu is not allowed for commercial use)