【问题标题】:Python OpenCV: Getting Stats out of Hough Circle DetectionPython OpenCV:从霍夫圆检测中获取统计信息
【发布时间】:2019-06-27 19:19:04
【问题描述】:

我和一个同学正在通过图像处理研究硬币计数器。我们使用了两种方法将硬币识别为圆圈。一方面是具有统计信息的连接组件,另一方面是 Hough 变换。 CC w/Stats 的优势是所有重要参数(例如像素区域)的直接输出。然而,CC 的 w/stats 会随着触摸图像中的硬币而减弱(硬币的中心无法正确识别)。 Hough Transformation 没有这个问题,并且很容易正确地检测到每个圆圈。但是,我们不知道如何在这里使用检测到的对象的数据。那么有没有办法用另一个函数来获取数据,或者甚至有办法从 CC w/Stats 和 Hough 变换生成混合代码?

import cv2
import numpy as np
import matplotlib.pyplot as plt

image='17.png'
img=cv2.imread(image,1)
img_orig=img.copy()
img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

img=cv2.GaussianBlur(img,(21,21),cv2.BORDER_DEFAULT)


all_circs=cv2.HoughCircles(img, cv2.HOUGH_GRADIENT,1,500,param1=110,param2=35,minRadius=200,maxRadius=600)
all_circs_rounded=np.uint32(np.around(all_circs))


count = 1
for i in all_circs_rounded[0, :]:
    cv2.circle(img_orig,(i[0],i[1],),i[2],(255,0,0),3)
    cv2.circle(img_orig,(i[0],i[1],),2,(255,0,0),3)
    cv2.putText(img_orig,"Coin"+str(count),(i[0]-70,i[1]+30),cv2.FONT_HERSHEY_SIMPLEX,1.1,(255,0,0),2)
    count+=1

print (all_circs_rounded)
print (all_circs_rounded.shape)
print ('I have found ' + str(all_circs_rounded.shape[1]) + ' coins')

plt.rcParams["figure.figsize"]=(16,9)
plt.imshow(img_orig)

【问题讨论】:

    标签: python opencv geometry detection hough-transform


    【解决方案1】:

    这个问题有几种可能的解决方案

    1. 您可以使用image segmentation with watershed。这种方法的优点是能够在图像中找到接触的硬币,因为您可以轻松地将硬币彼此分割。此外,分水岭允许您获得硬币的中心,您可以在其中进行额外的处理。

    2. 继续使用Hough Circle Transform。该函数返回各种参数,例如可用于查找圆面积的半径。这是获取半径的快速示例,您可以使用classic formula 查找区域。这种方法还可以让你轻松获取圆心。

    # detect circles in the image
    circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100)
    
    # ensure at least some circles were found
    if circles is not None:
        # convert the (x, y) coordinates and radius of the circles to integers
        circles = np.round(circles[0, :]).astype("int")
    
        # loop over the (x, y) coordinates and radius of the circles
        for (x, y, r) in circles:
            # draw the circle in the output image, then draw a rectangle
            # corresponding to the center of the circle
            cv2.circle(output, (x, y), r, (0, 255, 0), 4)
            cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
    
            # calculate area here
            ...
    
    1. 完全旋转并使用带有过滤的轮廓检测。可能的步骤是

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-14
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      相关资源
      最近更新 更多