我是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()
答案 0 :(得分:1)
对于视频分析,您必须连续从网络摄像头(在本例中)读取图像。所以你需要一个循环,如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()