日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

特征检测器 FeatureDetector

發布時間:2025/3/21 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 特征检测器 FeatureDetector 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

OpenCV提供FeatureDetector實現特征檢測及匹配

[cpp]?view plaincopy
  • 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是虛類,通過定義FeatureDetector的對象可以使用多種特征檢測方法。通過create()函數調用:

    [cpp]?view plaincopy
  • Ptr<FeatureDetector>?FeatureDetector::create(const?string&?detectorType);??
  • OpenCV 2.4.3提供了10種特征檢測方法:

    • "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
    圖片中的特征大體可分為三種:點特征、線特征、塊特征。 FAST算法是Rosten提出的一種快速提取的點特征[1],Harris與GFTT也是點特征,更具體來說是角點特征(參考這里)。 SimpleBlob是簡單塊特征,可以通過設置SimpleBlobDetector的參數決定提取圖像塊的主要性質,提供5種: 顏色?By color、面積?By area、圓形度?By circularity、最大inertia?(不知道怎么翻譯)與最小inertia的比例?By ratio of the minimum inertia to maximum inertia、以及凸性?By convexity. 最常用的當屬SIFT,尺度不變特征匹配算法(參考這里);以及后來發展起來的SURF,都可以看做較為復雜的塊特征。這兩個算法在OpenCV nonfree的模塊里面,需要在附件引用項中添加opencv_nonfree243.lib,同時在代碼中加入: [cpp]?view plaincopy
  • initModule_nonfree();??
  • 至于其他幾種算法,我就不太了解了?^_^
    一個簡單的使用演示: [cpp]?view plaincopy
  • int?main()??
  • {??
  • ??
  • ????initModule_nonfree();//if?use?SIFT?or?SURF??
  • ????Ptr<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?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(10000);??
  • ????return?0;??
  • }??

  • 特征檢測結果如圖:
    Box_in_scene


    Box
    特征點匹配結果:
    Match
    另一點需要一提的是SimpleBlob的實現是有Bug的。不能直接通過?Ptr<FeatureDetector> detector = FeatureDetector::create("SimpleBlob"); ?語句來調用,而應該直接創建?SimpleBlobDetector的對象: [cpp]?view plaincopy
  • ???????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));??
  • 以下是SimpleBlobDetector按顏色檢測的圖像特征:


    [1] Rosten. Machine Learning for High-speed Corner Detection, 2006

    (轉載請注明作者和出處:http://blog.csdn.net/xiaowei_cqu?未經允許請勿用于商業用途)

    總結

    以上是生活随笔為你收集整理的特征检测器 FeatureDetector的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。