Reputation: 21
I'm trying to do some image processing on a Raspberry Pi with Python and OpenCV. It works well so far except a low FPS rate. Even without any image processing and just with the code below I get only 10 FPS with 640x480 resolution. 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
Upvotes: 2
Views: 5720
Reputation: 427
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.
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.
Check these two posts for a more detailed explanation: limited framerate picamera v2
Upvotes: 1