因此,这段代码似乎很容易使用我的网络摄像头找到一个圆圈。但是,我希望每当找到一个圆圈时也画一个圆圈,而不是简单地关闭程序。我试图添加一个" cv2.circle(参数...)"代码,但它没有工作。任何人都可以帮助我吗?
import cv2
import numpy as np
import sys
color = (0,0,255)
cap = cv2.VideoCapture(0)
while(True):
gray = cv2.medianBlur(cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2GRAY),5)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 10, minRadius = 1, maxRadius = 20)
if circles != None: print "Circle There !"
cv2.imshow('video',gray)
if cv2.waitKey(1) == 27:# esc Key
break
cap.release()
cv2.destroyAllWindows()
答案 0 :(得分:0)
你可能想要搞乱cv2.HoughCircles函数中的参数(你甚至可以完全删除一些参数),但这应该可行。
cap = cv2.VideoCapture(0)
while(True):
gray = cv2.medianBlur(cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2GRAY),5)
circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT,1,10, param1=150,param2=40,minRadius=0,maxRadius=1000)
if circles != None:
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cgray,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cgray,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('video',cgray)
if cv2.waitKey(1) == 27:# esc Key
break
cap.release()
cv2.destroyAllWindows()