打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
OpenCV中的Blob分析演示

蓝字关注我们

微信公众号:OpenCV学堂

关注获取更多计算机视觉与深度学习知识

概述

Blob检测在传统灰度图像分析与测量中是常用功能之一,Blob检测可以快速从灰度图像中定位跟提取各种常见的几何形状,可以根据面积、灰度值、圆度、凸度、惯量进行过滤得到符合需求的各种Blob形状,实现检测的定位与检测。支持的五种度量过滤图示如下:

OpenCV中支持函数

OpenCV中已经实现了Blob对象检测算法,对应的函数如下:




cv::SimpleBlobDetector::create ( constSimpleBlobDetector::Params & parameters = SimpleBlobDetector::Params )


参数支持如下: ucharblobColor

// 支持的五种过滤方式






boolfilterByArea // 面积过滤,True表示启用 boolfilterByCircularity // 圆度过滤,True表示启用 boolfilterByColor // 值过滤,True表示启用 boolfilterByConvexity // 凸度过滤,True表示启用 boolfilterByInertia // 惯量过滤,True表示启用

// 每种方式的最小与最大参数阈值














floatmaxArea floatmaxCircularity floatmaxConvexity floatmaxInertiaRatio floatmaxThreshold floatminArea floatminCircularity floatminConvexity floatminDistBetweenBlobs floatminInertiaRatio size_tminRepeatability floatminThreshold floatthresholdStep

其中 圆度、凸度、惯量的取值范围均为[0, 1]之间。输入灰度图像,调用之后输出的是KeyPoint数据结构的List,其中KeyPoint结构中pt表示返回的每个Blob的中心位置,size表示宽度/直径。

案例:Blob分析

创建Blob对象与初始化参数设置的代码如下:





























params= cv.SimpleBlobDetector_Params # 面积过滤 params.blobColor = False params.filterByArea = False params.minArea = 100 params.maxArea = 800

# 圆度过滤, 取值范围 0 ~ 1params.filterByCircularity = False params.minCircularity = 0.8params.maxCircularity = 1.0

# 颜色过滤params.filterByColor = True params.minThreshold = 50params.maxThreshold = 100

# 凸度过滤, 取值范围 0 ~ 1params.filterByConvexity = False params.minConvexity = 0.98params.maxConvexity = 0.99

# 惯量过滤, 取值范围 0 ~ 1params.filterByInertia = False params.minInertiaRatio = 0.8params.maxInertiaRatio = 1.0

detector = cv.SimpleBlobDetector.create( params)

检测代码与运行结果如下:






gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)keypoints = detector.detect(gray)forkp inkeypoints: cv.circle(image, (np. int(kp.pt[ 0]), np. int(kp.pt[ 1])), 3, ( 0, 255, 0), -1, 8) cv.circle(image, (np. int(kp.pt[ 0]), np. int(kp.pt[ 1])), np. int(kp.size/ 2), ( 0, 0, 255), 2, 8)

运行结果如下:

根据面积过滤的Blob分析结果如下:1000~2000

根据圆度过滤的Blob分析结果如下0~0.7:

根据圆度过滤的Blob分析结果如下0.8~1.0:

根据凸度过滤的Blob分析结果如下0.98~1.0:

找到了唯一没有缺口的圆

根据惯量过滤的Blob分析结果如下0.0~0.2:

直线的惯量接近于0, 圆的惯量接近于1

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
opencv笔记
支持向量机(SVM)介绍 — OpenCV 2.3.2 documentation
ADAS-交通标牌检测与识别
微信二维码引擎OpenCV开源!3行代码让你拥有微信扫码能力
在OpenCV-Python 中用YOLO 目标检测
使用Python OpenCV预测年龄与性别
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服