我在航空图像上运行一个简单的检测器,根据我设置的参数检测斑点(我现在不喜欢干扰物)。
最后,我需要在图像上显示水滴的坐标(x,y)(至少是大于某个区域的坐标),或者将它们存储在列表中
这是我的密码
# Standard imports
import cv2
import numpy as np;
# Read image
img = cv2.imread("image.jpg", cv2.IMREAD_GRAYSCALE)
# Taking a matrix of size 5 as the kernel
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
# The first parameter is the original image,
# kernel is the matrix with which image is
# convolved and third parameter is the number
# of iterations, which will determine how much
# you want to erode/dilate a given image.
img = cv2.equalizeHist(img)
img_dilation = cv2.erode(img, kernel, iterations=1)
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 40 #10
params.maxThreshold = 200 #200
# Filter by Area.
params.filterByArea = True # True
params.minArea = 16 # 3*3
params.maxArea = 121 #11*11 pixel
# Filter by Circularity
params.filterByCircularity = True #True
params.minCircularity = 0.785 #0.1
# Filter by Colr
params.filterByColor = True #True
params.blobColor = 0 #0.1
# Filter by Convexity
params.filterByConvexity = True #True
params.minConvexity = 0.1 #0.87
# Filter by Inertia
params.filterByInertia = True #True
params.minInertiaRatio = 0.25 #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(img_dilation)
# 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
total_count = 0
for i in keypoints:
total_count = total_count + 1
im_with_keypoints = cv2.drawKeypoints(img_dilation, keypoints, np.array([]), (255, 0, 0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show blobs
cv2.imwrite("Keypoints.jpg", im_with_keypoints)
cv2.waitKey(0)
有什么想法吗
目前没有回答
相关问题 更多 >
编程相关推荐