我正在尝试通过方程实现圆形霍夫变换,r = 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)
此代码中仍然需要一些升级以使累加器空间的进程更快。
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