Opencv 如何在视频中使用圆检测
我对python和OpenCV非常陌生。我想做的是用hough圆在视频中的某个部分上找到一个圆,并在该圆在摄像机视野中移动时跟踪该圆。我可以在静止图像上使用hough圆。到目前为止,这就是我所拥有的,但我认为这离工作还有一段距离Opencv 如何在视频中使用圆检测,opencv,Opencv,我对python和OpenCV非常陌生。我想做的是用hough圆在视频中的某个部分上找到一个圆,并在该圆在摄像机视野中移动时跟踪该圆。我可以在静止图像上使用hough圆。到目前为止,这就是我所拥有的,但我认为这离工作还有一段距离 import cv2 import numpy as np img = cv2.VideoCapture(0) circles = cv2.HoughCircles(img,cv2.cv.CV_HOUGH_GRADIENT,1,20,
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()
对于视频分析,您必须连续从网络摄像头(在本例中)读取图像。因此,您需要一个循环,如中的教程所示
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()