python斑点检测
对于简单的场景管用,复杂的场景效果不明显。
方法一:基于LoG算子的圆斑检测。
这是常用的斑点检测方法,可参考http://doc.okbase.net/ronny/archive/102540.html。
此方法的问题是,图像中不是圆形的斑点也会检测出来,还需要进一步的判断,这使得算法的效率不高。
/* 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; */
LoG检测
利用高斯拉普拉斯LOG算子检测图像斑点较DoH,Harris和其它点检测方法稳定性更好,抗图像中噪声的能力更强
-
#!/usr/bin/env python
-
# -*- coding: utf-8 -*-
-
-
# Standard imports
-
import os
-
-
import cv2
-
import numpy as np
-
-
-
path=r"Images/"
-
-
files=os.listdir(path)
-
for file in files:
-
-
# Read image
-
im = cv2.imread(path+file)
-
im_o = cv2.resize(im, (800,600))
-
-
im_gauss = cv2.cvtColor(im_o, cv2.COLOR_RGB2GRAY)
-
im_gauss = cv2.GaussianBlur(im_gauss, (3, 3), 0)
-
ret, im = cv2.threshold(im_gauss, 30, 255, 0)
-
cv2.imshow("o", im)
-
# Setup SimpleBlobDetector parameters.
-
params = cv2.SimpleBlobDetector_Params()
-
-
# Change thresholds
-
params.minThreshold = 10
-
params.maxThreshold = 200
-
-
# Filter by Area.
-
params.filterByArea = True
-
params.minArea = 16
-
-
# Filter by Circularity
-
params.filterByCircularity = True
-
params.minCircularity = 0.3
-
-
# Filter by Convexity
-
params.filterByConvexity = True
-
params.minConvexity = 0.57
-
-
# Filter by Inertia
-
params.filterByInertia = True
-
params.minInertiaRatio = 0.01
-
-
# Create a detector with the parameters
-
ver = (cv2.__version__).split('.')
-
if int(ver[0]) < 3:
-
detector = cv2.SimpleBlobDetector(params)
-
else:
-
detector = cv2.SimpleBlobDetector_create(params)
-
-
# Detect blobs.
-
keypoints = detector.detect(im)
-
-
# Draw detected blobs as red circles.
-
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures
-
# the size of the circle corresponds to the size of blob
-
-
im_with_keypoints = cv2.drawKeypoints(im_o, keypoints, np.array([]), (0, 0, 255),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
-
-
# Show blobs
-
cv2.imshow("Keypoints", im_with_keypoints)
-
cv2.waitKey(0)
-
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/96865498
- 点赞
- 收藏
- 关注作者
评论(0)