我正在尝试制作一个简单的程序来检测图像中的圆圈。我已经编写了这段代码,结果可以在附图中看到。有人可以告诉我,我做错了什么?
import time
import cv2
import imutils
import numpy as np
img=cv2.imread('circle.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
binary=cv2.threshold(gray,150,255,cv2.THRESH_BINARY)[1]
cv2.imshow('binary',binary)
circles=cv2.HoughCircles(binary,cv2.HOUGH_GRADIENT,1,50,50,30,5,100)
if circles is not None:
circles=np.round(circles[0,:]).astype("int")
for i in circles:
cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),4)
cv2.circle(img,(i[0],i[1]),2,(0,0,255),3)
else:
print"no circle"
cv2.imshow('circle',img)
k=cv2.waitKey(0)
if k==27:
cv2.destroyAllWindows()