blob(斑點)特征,SimpleBlobDetector(OpenCV案例源碼detect_blob.cpp解讀)


Blob是指圖像中的一塊連通區域,Blob分析就是對前景/背景分離后的二值圖像,進行連通域提取和標記。

知識點就是SimpleBlobDetector的使用,blob(斑點)篩選條件:斑點顏色、面積、圓度、慣性率、凸度,參數解讀鏈接

#include<opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;
int main()
{
    Mat src=imread("D:/sunflower.png");
    //*參數設置,以下都是默認參數
 SimpleBlobDetector::Params pDefaultBLOB;
    pDefaultBLOB.thresholdStep = 10;
    pDefaultBLOB.minThreshold = 50;
    pDefaultBLOB.maxThreshold = 220;
    pDefaultBLOB.minRepeatability = 2;
    pDefaultBLOB.minDistBetweenBlobs = 10;
    pDefaultBLOB.filterByColor = true;
    pDefaultBLOB.blobColor = 0;
    pDefaultBLOB.filterByArea = true;
    pDefaultBLOB.minArea = 25;
    pDefaultBLOB.maxArea = 5000;
    pDefaultBLOB.filterByCircularity = false;
    pDefaultBLOB.minCircularity = 0.8f;
    pDefaultBLOB.maxCircularity = (float)3.40282e+038;
    pDefaultBLOB.filterByInertia = true;
    pDefaultBLOB.minInertiaRatio = 0.1f;
    pDefaultBLOB.maxInertiaRatio = (float)3.40282e+038;
    pDefaultBLOB.filterByConvexity = true;
    pDefaultBLOB.minConvexity = 0.95f;
    pDefaultBLOB.maxConvexity = (float)3.40282e+038;
    //*用參數創建對象
    Ptr<SimpleBlobDetector> blob=SimpleBlobDetector::create(pDefaultBLOB); //Ptr<SimpleBlobDetector> blob=SimpleBlobDetector::create();//默認參數創建
    //*blob檢測
    vector<KeyPoint> key_points;
 blob->detect(src,key_points);
    Mat outImg;
    //*繪制結果
    drawKeypoints(src,key_points,outImg,Scalar(0,0,255));
    imshow("blob",outImg);

    waitKey();
    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM