【问题标题】:How to implement circle detection by using circle equation?如何使用圆方程实现圆检测?
【发布时间】:2017-05-10 05:43:44
【问题描述】:

我正在尝试通过方程式实现circular hough transformr = sqrt((x-h)^2-(y-k)^2) 用于从图像中检测圆圈。

我应用了像高斯模糊这样的步骤列表,精明的。之后,如果半径和边界点可用,我将不知道如何实现上述方程。实施后,我将获得包含检测圆的半径和中心的累加器空间。我想用opencv的HoughCircle函数来实现。有什么想法可以帮助我吗?这需要很多时间。

import numpy as np
import cv2
import math

image = cv2.imread(imagepath)

h, w = image.shape[:2]
print h, w

grayimg = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

bimg = cv2.bilateralFilter(grayimg, 5, 175, 175)

cann = cv2.Canny(bimg,100,200)

pixel = np.argwhere(cann == 255)


accum = []
ct = 0
for r in range(10,21):
    for h in range(0,20):
        for k in range(0,20):
            for p in pixel:
                print r,h,k,p
                xpart = (h - p[0])**2
                ypart = (k - p[1])**2
                rhs = xpart + ypart
                lhs = r * r
                if(lhs == rhs):
                    accum.append((r,(h,k),p))

print len(accum)
cv2.waitKey(0)

【问题讨论】:

  • 你的问题有点不清楚,能不能详细解释一下?
  • 看看霍夫变换
  • @Rosa Gronchi 我想在没有霍夫变换的情况下实现。
  • @ZdaR 考虑一张包含圆形矩阵的图像。我想实现给定的圆检测方程。对于上式,x 和 y 是边缘检测图像的边界点,h,k 可以是图像上的每个点。如果满足上述方程,则将得出圆心值和圆半径。对于这种情况,半径为 10 到 20。
  • @Zara 你已经在使用霍夫变换(从像素空间到方程参数空间)... ;)

标签: python opencv geometry


【解决方案1】:

在此代码中仍然需要一些升级来使累加器空间的处理速度更快。

accum = [[[0 for r in range(10,21)]for h in range(0,30)]for k in range(0,30)]
print accum
ct = 0
for r in range(10,21):
    for h in range(0,30):
        for k in range(0,30):
            for p in pixel:
                #print r,h,k,p
                xpart = (h - p[0])**2
                ypart = (k - p[1])**2
                rhs = xpart + ypart
                lhs = r * r
                if(lhs == rhs):
                    accum[k][h][r-10] += 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    相关资源
    最近更新 更多