我是python和OpenCV的新手。我想做的是使用霍夫圆在视频的一部分上找到一个圆,并在该圆在摄像机视场中移动时对其进行跟踪。我可以在静止图像上使用霍夫圆。到目前为止,这是我所拥有的,但是我认为它离工作很近。
import cv2
import numpy as np
img = cv2.VideoCapture(0)
circles = cv2.HoughCircles(img,cv2.cv.CV_HOUGH_GRADIENT,1,20,
param1=200,param2=100,minRadius=0,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[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.imshow('detected circles',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
最佳答案
对于视频分析,您必须连续读取网络摄像头中的图像(在这种情况下)。因此,您需要一个循环,如OpenCV中的教程所示。
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
#read frame from capture
img = cap.read()
##############################
# here do the whole stuff with circles and your actual image
##############################
cv2.imshow('show image', img)
#exit condition to leave the loop
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cv2.destroyAllWindows()
cap.release()
关于opencv - 如何在视频中使用圆圈检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22159593/