opencv3
- opencv3 推荐度:
- 相关推荐
opencv3
基于局部极值的分水岭算法斑点检测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.hpp
中SimpleBlobDetector
的定义:
/** @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 fromminThreshold (inclusive) to maxThreshold (exclusive) with distance thresholdStep betweenneighboring thresholds.
2. Extract connected components from every binary image by findContours and calculate theircenters.
3. Group centers from several binary images by their coordinates. Close centers form one group thatcorresponds 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 andsizes 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 ¶meters = SimpleBlobDetector::Params());CV_WRAP virtual String getDefaultName() const;
};
最新文章
- Http Digest 认证
- “脱离应用开发者的数据库,不会成功”,黄东旭万字长文剖析数据库发展新趋势...
- android studio 打包cocos creator项目
- 概率图模型(PGM)综述
- 大数定律,方差
- [SOA介绍]什么是SOA?
- mmap。
- Specification 参数的用法
- vss服务器的简单使用
- ext4 介绍
- c语言怎么键盘输入数据0停止,《C语言》上机考试题目.PDF
- jmeter性能测试脚本录制不了的几种情况
- 磁盘分区形式:主启动记录(MBR)和全局唯一标识分区表(GPT)
- Python爬虫爬取动态网页
- 高斯函数详解
- 渗透常用SQL注入语句大全
- socat 虚拟串口在 linux OS中如何实现?