【发布时间】:2020-11-06 19:27:03
【问题描述】:
我正在尝试在所附图像中找到所有圆形粒子。这是我唯一拥有的图片(连同它的反面)。
我已阅读this post,但我无法使用 hsv 值进行阈值处理。我尝试过使用霍夫变换。
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, dp=0.01, minDist=0.1, param1=10, param2=5, minRadius=3,maxRadius=6)
并使用以下代码进行绘图
names =[circles]
for nums in names:
color_img = cv2.imread(path)
blue = (211,211,211)
for x, y, r in nums[0]:
cv2.circle(color_img, (x,y), r, blue, 1)
plt.figure(figsize=(15,15))
plt.title("Hough")
plt.imshow(color_img, cmap='gray')
以下代码用于绘制掩码:
for masks in names:
black = np.zeros(img_gray.shape)
for x, y, r in masks[0]:
cv2.circle(black, (x,y), int(r), 255, -1) # -1 to draw filled circles
plt.imshow(black, gray)
【问题讨论】:
-
使用 cv2.contourArea 的简单轮廓区域过滤应该可以工作
标签: python python-3.x opencv image-processing computer-vision