Blob检测器

本文转载自https://blog.csdn.net/Good_Boyzq/article/details/72811687

  • Opencv实例

效果图:

                                                                                                       原图

                                                                                                        结果图        

代码:


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

using namespace std;
using namespace cv;

/*
SimpleBlobDetector::Params::Params()  
{  
	thresholdStep = 10;       //二值化的阈值步长,即公式1的t  
	minThreshold = 50;        //二值化的起始阈值,即公式1的T1  
	maxThreshold = 220;       //二值化的终止阈值,即公式1的T2  	 
	minRepeatability = 2;     //重复的最小次数,只有属于灰度图像斑点的那些二值图像斑点数量大于该值时,该灰度图像斑点才被认为是特征点 
	minDistBetweenBlobs = 10; //最小的斑点距离,不同二值图像的斑点间距离小于该值时,被认为是同一个位置的斑点,否则是不同位置上的斑点

	filterByColor = true;     //斑点颜色的限制变量  
	blobColor = 0;            //表示只提取黑色斑点;如果该变量为255,表示只提取白色斑点  

	filterByArea = true;      //斑点面积的限制变量  
	minArea = 25;             //斑点的最小面积  
	maxArea = 5000;           //斑点的最大面积  

	filterByCircularity = false;                          //斑点圆度的限制变量,默认是不限制  
	minCircularity = 0.8f;                                //斑点的最小圆度  
	maxCircularity = std::numeric_limits<float>::max();   //斑点的最大圆度,所能表示的float类型的最大值 

	filterByInertia = true;                               //斑点惯性率的限制变量  
	//minInertiaRatio = 0.6;  
	minInertiaRatio = 0.1f;                               //斑点的最小惯性率  
	maxInertiaRatio = std::numeric_limits<float>::max();  //斑点的最大惯性率  

	filterByConvexity = true;                             //斑点凸度的限制变量  
	//minConvexity = 0.8;  
	minConvexity = 0.95f;                                 //斑点的最小凸度  
	maxConvexity = std::numeric_limits<float>::max();     //斑点的最大凸度  
}  */
int main(){
    Mat img = imread("1.jpg");
    
    SimpleBlobDetector::Params params;
    //阈值控制
    params.minThreshold = 10;
    params.maxThreshold = 200;
    //像素面积大小控制
    params.filterByArea = true;
    params.minArea = 1000;
    //圆度
    params.filterByCircularity = false;
    params.minCircularity = 0.7;
    //凸度
    params.filterByConvexity = true;
    params.minConvexity = 0.9;
    //惯性率
    params.filterByInertia = false;
    params.minInertiaRatio = 0.5;
    
    //参数初始化BLOB检测器
    Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create();
    vector<KeyPoint> keypoints;

    //检测得到特征并绘制
    detector->detect(img,keypoints);
    Mat img_with_keypoints;
    drawKeypoints(img,keypoints,img_with_keypoints,Scalar(0,0,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    imshow("keypoints",img_with_keypoints);
    waitKey(0);
    return 0;
}

                                                                              

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值