opencv3--斑点检测simpleBlobDetector

基于局部极值的分水岭算法斑点检测simpleBlobDetector

分为以下几步:
  1.对一张图片,设定一个低阈值minThreshold,设定一个高阈值maxThreshold,在设定一个阈值步进thresholdStep,然后从低阈值到高阈值按照阈值步进取一系列的阈值,即对[minThreshold,maxThreshold)区间,以thresholdStep为间隔,用每一个阈值对图像进行二值化,得到一系列图像;
  2.对每张二值图片,使用findcontours查找这些图像的边,并计算每一个轮廓的中心;
  3.根据2得到每一个图片的轮的中心点,全部放在一起。定义一个最小距离,在这个距离区域内的特征中心点[由minDistBetweenBlobs控制多少才算接近]被归为一个group,对应一个bolb特征,得到特征点集合。
  4.从3得到的那些点,估计最后的blob特征和相应半径,并以key points返回。对特征点进行相应的过滤,例如颜色过滤,面积过滤等

opencv中检测Blobs的类为SimpleBlobDetector,这个类在opencv中的定义如下:

// Blob算子参数
	SimpleBlobDetector::Params params;
	params.thresholdStep = 10;    //二值化的阈值步长
	
	//阈值控制
	params.minThreshold = 20;
	params.maxThreshold = 200;
	
    //斑点颜色(0黑色,255白色)
	params.filterByColor = true;
	params.blobColor = 0;
	
    //像素面积大小控制
	params.filterByArea = true;
	params.minArea = 200;
	params.maxArea = 80000;
	
	//形状(凸)
    params.filterByCircularity = false;
    params.minCircularity = 0.7;
    
    //形状(凹)
    params.filterByConvexity = true;
    params.minConvexity = 0.9;
    
    //形状(圆)的饱满度
	params.filterByCircularity = true;
	params.minCircularity = 0.5;

	Ptr<FeatureDetector> blobDetector = SimpleBlobDetector::create(params);
	//定义检测的圆心点
    vector<KeyPoint> keypoints;
    blobDetector->detect(img,keypoints);

    //在img上显示圆心点
    Mat img_with_keypoint;
    drawKeypoints(img,keypoints,img_with_keypoint,Scalar(0,0,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    
	// 提取圆点特征的圆心(相机标定使用)
	Size boardSizea(2,3;
	//缓存检测到的角点
	vector<Point2f> imagePointsBuf;
	bool found = findCirclesGrid(imageInput, boardSizea, imagePointsBuf, CALIB_CB_SYMMETRIC_GRID | CALIB_CB_CLUSTERING, blobDetector);
	drawChessboardCorners(imageInput, boardSizea, imagePointsBuf, found);

opencv3 的features2d.hppSimpleBlobDetector的定义:

/** @brief Class for extracting blobs from an image. :

The class implements a simple algorithm for extracting blobs from an image:

1.  Convert the source image to binary images by applying thresholding with several thresholds from
    minThreshold (inclusive) to maxThreshold (exclusive) with distance thresholdStep between
    neighboring thresholds.
2.  Extract connected components from every binary image by findContours and calculate their
    centers.
3.  Group centers from several binary images by their coordinates. Close centers form one group that
    corresponds to one blob, which is controlled by the minDistBetweenBlobs parameter.
4.  From the groups, estimate final centers of blobs and their radiuses and return as locations and
    sizes of keypoints.

This class performs several filtrations of returned blobs. You should set filterBy\* to true/false
to turn on/off corresponding filtration. Available filtrations:

-   **By color**. This filter compares the intensity of a binary image at the center of a blob to
blobColor. If they differ, the blob is filtered out. Use blobColor = 0 to extract dark blobs
and blobColor = 255 to extract light blobs.
-   **By area**. Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive).
-   **By circularity**. Extracted blobs have circularity
(\f$\frac{4*\pi*Area}{perimeter * perimeter}\f$) between minCircularity (inclusive) and
maxCircularity (exclusive).
-   **By ratio of the minimum inertia to maximum inertia**. Extracted blobs have this ratio
between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive).
-   **By convexity**. Extracted blobs have convexity (area / area of blob convex hull) between
minConvexity (inclusive) and maxConvexity (exclusive).

Default values of parameters are tuned to extract dark circular blobs.
 */
class CV_EXPORTS_W SimpleBlobDetector : public Feature2D
{
public:
  struct CV_EXPORTS_W_SIMPLE Params
  {
      CV_WRAP Params();
      CV_PROP_RW float thresholdStep;
      CV_PROP_RW float minThreshold;
      CV_PROP_RW float maxThreshold;
      CV_PROP_RW size_t minRepeatability;
      CV_PROP_RW float minDistBetweenBlobs;

      CV_PROP_RW bool filterByColor;
      CV_PROP_RW uchar blobColor;

      CV_PROP_RW bool filterByArea;
      CV_PROP_RW float minArea, maxArea;

      CV_PROP_RW bool filterByCircularity;
      CV_PROP_RW float minCircularity, maxCircularity;

      CV_PROP_RW bool filterByInertia;
      CV_PROP_RW float minInertiaRatio, maxInertiaRatio;

      CV_PROP_RW bool filterByConvexity;
      CV_PROP_RW float minConvexity, maxConvexity;

      void read( const FileNode& fn );
      void write( FileStorage& fs ) const;
  };

  CV_WRAP static Ptr<SimpleBlobDetector>
    create(const SimpleBlobDetector::Params &parameters = SimpleBlobDetector::Params());
  CV_WRAP virtual String getDefaultName() const;
};
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值