简体   繁体   English

在Raspberry Pi上使用Python和OpenCV实现低FPS

[英]Low FPS with Python, OpenCV on Raspberry Pi

I'm trying to do some image processing on a Raspberry Pi with Python and OpenCV. 我正在尝试使用Python和OpenCV在Raspberry Pi上进行一些图像处理。 It works well so far except a low FPS rate. 到目前为止,它的效果很好,但FPS速率较低。 Even without any image processing and just with the code below I get only 10 FPS with 640x480 resolution. 即使没有任何图像处理,仅使用下面的代码,我也只能获得10 FPS,分辨率为640x480。 Is there a faster way to capture the video stream? 有没有更快的方法来捕获视频流? Do I something wrong here? 我在这里有问题吗?

import numpy as np
import cv2
import time
from picamera.array import PiRGBArray
from picamera import PiCamera

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
start = time.time()

for img in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):

    frame = img.array
    rawCapture.truncate(0)
    end = time.time()
    print 'fps:', int(round(1 / (end - start)))
    start = time.time()

Thank you so far. 到目前为止谢谢你。

regards 问候

From the best of my knowledge, the hardware always produces YUV (I420) and conversion to BGR or RGB is done as an extra vector sw stage, thus reducing your frames per second. 据我所知,硬件始终会产生YUV (I420),并作为额外的矢量sw阶段完成向BGR或RGB的转换,从而减少了每秒的帧数。

I would suggest creating a thread dedicated solely to your IO pipeline, reducing latency and potentially increasing your fps, however I highly doubt you will be able to achieve the glorious 90fps (at 640x480) with the BGR model. 我建议创建一个专门用于您的IO管道的线程,以减少延迟并可能提高fps,但是我非常怀疑您是否能够使用BGR模型实现出色的90fp​​s(640x480)。

Check these two posts for a more detailed explanation: limited framerate picamera v2 检查这两个帖子以获取更详细的解释: 有限帧率picamera v2

https://raspberrypi.stackexchange.com/questions/22040/take-images-in-a-short-time-using-the-raspberry-pi-camera-module https://raspberrypi.stackexchange.com/questions/22040/take-images-in-a-short-time-using-the-raspberry-pi-camera-module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM