Blob Detection Using OpenCV

本系列主要为learn opencv的翻译和学习,整理。
参考:https://www.learnopencv.com/blob-detection-using-opencv-python-c/

斑点检测
斑点是指图像中有相同性质的像素组成的连通区域

python代码:

import cv2
import numpy as np;
im = cv2.imread(“blob.jpg”, cv2.IMREAD_GRAYSCALE)
detector = cv2.SimpleBlobDetector()
keypoints = detector.detect(im)
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255),
cv2.imshow(“Keypoints”, im_with_keypoints)
cv2.waitKey(0)

原理:
1、将图像按照minThreshold和maxThreshold,生成一系列二值图, minThreshold + step ,minThreshold + 2* step
step = (maxThreshold - minThreshold)/n
2、在二值图中将白色像素点连接起来,获得一系列连通区域,区域就是二值图的斑点
3、将具有相同中心的各个二值图斑点合并
4、计算合并后斑点的半径和圆心

斑点过滤方式
1、颜色,2、大小,3、形状

python 代码

params = cv2.SimpleBlobDetector_Params()

params.minThreshold = 10;
params.maxThreshold = 200;

params.filterByArea = True
params.minArea = 1500

params.filterByCircularity = True
params.minCircularity = 0.1

params.filterByConvexity = True
params.minConvexity = 0.87

params.filterByInertia = True
params.minInertiaRatio = 0.01

ver = (cv2.version).split(’.’)
if int(ver[0]) < 3 :
detector = cv2.SimpleBlobDetector(params)
else :
detector = cv2.SimpleBlobDetector_create(params)

Blob Detection Using OpenCV_第1张图片

你可能感兴趣的:(图像算法,python,opencv——图像算法)