int main() { initModule_nonfree();//if use SIFT or SURF Ptr detector = FeatureDetector::create( "SIFT" ); Ptr descriptor_extractor = DescriptorExtractor::crea http://www.szhaoexport.com/linked/20130310.do te( "SIFT" ); Ptr 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 keypoints1,keypoints2; detector->detect( img1, keypoints1 ); detector->detect( img2, keypoints2 ); cout <<"img1:"<< keypoints1.size() << " points img2:" <" << 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; //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 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; } 特徵檢測成果如圖: http://www.6699ysk.info/linked/20130310.do