我一直在尝试找出如何在网络摄像头feed上应用霍夫变换。但是我收到错误消息,它没有适当的格式,即使我对其进行了灰度缩放以检查它是否在uint8中也是如此。
cap = cv2.VideoCapture(1)
while(True):
ret, frame = cap.read()
frame = cv2.medianBlur(frame,5)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
###
#HughCircles Detection TEST
circles = cv2.HoughCircles(frame,cv2.HOUGH_GRADIENT,1,50,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint16(np.around(circles))
if circles is None:
for i in circles[0,:]:
# draw the outer circle
cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3)
#
###
# Display the resulting frame
cv2.imshow('Board',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
最佳答案
好吧,在另一篇文章中,我看到圈子在没有可见内容的情况下实际上返回了None,因此必须有一个if,以便它不表示None。
cap = cv2.VideoCapture(1)
while(True):
ret, frame = cap.read()
frame = cv2.medianBlur(frame,5)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
###
#HughCircles Detection TEST
circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT,1,50,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint16(np.around(circles))
if circles != None:
for i in circles[0,:]:
# draw the outer circle
cv2.circle(gray,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(gray,(i[0],i[1]),2,(0,0,255),3)
#
###
# Display the resulting frame
cv2.imshow('Board',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
关于python-2.7 - 使用OpenCV在实时Feed上进行霍夫变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33025729/