Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何提高FPS并减少滞后I';我在用树莓圆周率寻找圆圈时得到了什么?_Python_Performance_Raspberry Pi_Hough Transform - Fatal编程技术网

Python 如何提高FPS并减少滞后I';我在用树莓圆周率寻找圆圈时得到了什么?

Python 如何提高FPS并减少滞后I';我在用树莓圆周率寻找圆圈时得到了什么?,python,performance,raspberry-pi,hough-transform,Python,Performance,Raspberry Pi,Hough Transform,我有个小问题: 目前,我正在用我的树莓圆周率和一个网络摄像头来探测圆圈。 有很多关于用HoughCircles检测python中的圆的主题,我已经做到了。不过它有点太慢了:它给了我几秒钟的巨大延迟。 在这几秒钟内,它一直打印“未检测到圆圈”,即使我确信我的圆圈一直在摄像头前。几秒钟后,它打印出中心的位置 我的代码粘贴在下面,任何帮助都是感激的 import cv2 import numpy as np import time camera_port = 0 ramp_frames = 20 #

我有个小问题: 目前,我正在用我的树莓圆周率和一个网络摄像头来探测圆圈。 有很多关于用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:
这是非常不需要的

见:

尝试:

我认为这不会解决你的问题,但至少你的问题看起来更像蟒蛇


祝你好运

这不起作用,可能是因为如果检测到圆,则圆是一个数组,如果未检测到圆,则为“非类型”对象?我猜这是真的。。。也许我不应该在不了解您使用的软件包的情况下回答。然而,我仍然认为这样的说法并不是很像蟒蛇,因为你在重复你自己:“不是没有”一定有一个更整洁的方式。但现在,考虑我的答案,因为没有张贴…(只是想一想……相机的帧速率是多少,可能会高于20帧/秒?因为据我所知,网络摄像头可以努力找到正确的照明。这可能会导致更长的调整时间(=更多帧).尝试增加丢弃帧的数量…cv2的文档在哪里?你让我感兴趣!我在附近搜索了一段时间,但找不到它,尽管cv2似乎是python标准库的一部分?
if circles: