有个小问题: 目前,我正在使用带有网络摄像头的覆盆子 pi 检测圆圈。 有很多关于使用 HoughCircles 在 python 中检测圆的主题,我已经开始工作了。虽然它有点太慢了:它给了我几秒钟的巨大滞后。 在这几秒钟内,它一直打印“未检测到圆圈”,即使我确定我的圆圈在网络摄像头前。几秒钟后,它打印出中心的位置。
我的代码粘贴在下面,感谢任何帮助!
import cv2
import numpy as np
import time
camera_port = 0
ramp_frames = 20 #throw away to make it adjust to light levels
camera = cv2.VideoCapture(camera_port) #define camera class
retval = camera.set(3,320) #width of frame
retval = camera.set(4,240) #height of frame
def get_image(): #function to get 1 image
retval, im = camera.read()
return im
for i in xrange(ramp_frames): #adjust to light levels, throw away 20 frames
temp = get_image()
while True:
time.sleep(1)
camera_capture = get_image() # Take the actual image we want to keep
#processing
img = camera_capture
cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(cimg,cv2.cv.CV_HOUGH_GRADIENT,1,1,param1=200,param2=80,minRadius=0,maxRadius=0)
if circles is not None:
x=circles[0][0][0]
y=circles[0][0][1]
print "x= ",x,"y= ",y
else:
print "no circles detected"
最佳答案
虽然对你想做的事情一无所知,但我知道
if circles is not None:
非常不需要!
参见:"Python Boolean Operations"
尝试:
if circles:
我认为它不会解决您的问题,但至少您的问题看起来更像 pythonic! ;)
祝你好运!
关于python - 在使用 Raspberry Pi 寻找圆圈时,如何提高 FPS 并减少延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20521816/