![](/img/trans.png)
[英]OpenCV Python - Draw circle at random position in webcam video feed
[英]How to draw a circle whenever a circle is found by my webcam using OpenCV?
因此,这段代码似乎很容易使用我的网络摄像头找到一个圆圈。 但是,我希望它在找到一个圆圈时也能画一个圆,而不是简单地关闭程序。 我试图在代码中添加一个“ cv2.circle(parameters ...)”,但是它不起作用。 谁能帮我?
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()
您可能会想弄混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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.