【发布时间】:2017-05-08 15:50:34
【问题描述】:
我正在尝试使用 houghcircles() 检测此裁剪图像中的小圆圈。我试图改变它的参数,但是当我将 param2 增加到 50 以上时它会出错,当它的值小于 100 时 maxRadius 也会出错。现在它运行但性能很差 这是原始图像:
这是我的代码:
from imutils.perspective import four_point_transform
from imutils import contours
import numpy as np
import argparse
import imutils
import cv2
im = cv2.imread('crop.png')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray, 200, 255,cv2.THRESH_BINARY)
cimg = cv2.cvtColor(thresh,cv2.COLOR_GRAY2BGR)
c = cv2.HoughCircles(thresh, cv2.HOUGH_GRADIENT, 0.5, 41, param1=70,
param2=30, minRadius=10,maxRadius=175)
c = np.uint16(np.around(c))
for i in c[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.namedWindow('img',cv2.WINDOW_NORMAL)
cv2.resizeWindow('img', 800,800)
cv2.imshow('img',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
请问,我应该如何更改参数?
【问题讨论】:
标签: python opencv image-processing hough-transform