如果使用OpenCV的HoughCircles,是否有建议的方法来确定minRadius以在图像中找到1个圆?

问题描述 投票:0回答:1

我需要找出最佳的方法来选择要在OpenCV cv2.HoughCircles function中使用的minRadius值。

我正在努力提高Tensorflow CNN的准确性,该Tensorflow CNN可以进行美国稀有硬币分类。目前,CNN正在审核> 从300x300到1024x1024的所有不同大小的图像

的1万张图像

为了提高模型的准确性,我尝试在训练之前将硬币从图像中拉出,并且仅在硬币上而不是在其周围训练模型。

下面的代码可以将硬币检测为圆形,但是我必须尝试几个minRadius值才能使HoughCircles函数正常工作。

[在某些情况下,minRadius = 270在600x600和785x1024上有效,而在其他情况下,只有r = 200在600x600和785x1024上有效,但在785x1024上无效。在其他情况下,只有r = 318有效,而没有317或319有效。我没有找到一致的方法。

问题:是否有推荐的方法来确定minRadius以便在图像中找到1个圆?假设图像大小不同且硬币占图像的50%至90%]]

以下是典型图像的示例:https://i.ebayimg.com/images/g/r5oAAOSwH8VeHNBf/s-l1600.jpghttps://i.ebayimg.com/images/g/~JsAAOSwGtdeyFfU/s-l1600.jpg

image = cv2.imread(r"C:\testimages\70a.jpg")
output = image.copy()
height, width = image.shape[:2]

minRadius = 200
maxRadius =0

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(image=gray, 
                           method=cv2.HOUGH_GRADIENT, 
                           dp=1.2, 
                           minDist=200*minRadius, #something large since we are looking for 1
                           param1=200,
                           param2=100,
                           minRadius=minRadius,
                           maxRadius=maxRadius
                          )

#Draw the circles detected
if circles is not None:
    # convert the (x, y) coordinates and radius of the circles to integers
    circlesRound = np.round(circles[0, :]).astype("int")
    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circlesRound:
        cv2.circle(output, (x, y), r, (0, 255, 0), 4)

    plt.imshow(output)
else:
    print ('No circles found')

我需要找出最好的方法来选择在OpenCV cv2.HoughCircles函数中使用的minRadius值。我正在努力提高使用美国稀有硬币的Tensorflow CNN的准确性...

python image opencv tensorflow crop
1个回答
1
投票

这是通过将椭圆拟合从阈值图像提取的最大轮廓来实现此目的的另一种方法。如果需要,可以使用椭圆的主要半径和次要半径作为霍夫圆的近似值。

© www.soinside.com 2019 - 2024. All rights reserved.