Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv low fps on raspberry pi 4


I have a raspberry pi 4 and a PiCamera and I'm trying to get video stream with python and opencv from PICamera and display it on the screen. With low resolutions (320x240) everything works fine, but with resolutions 800x600 .. 720p .. 1080p the fps is very low.

With the command raspvid ( raspivid -o - -t 0 -w 1920 -h 1080 -fps 30 -b 250000 ) the video stream displayed is perfect, in high resolution and practically in real time. Everything leads me to believe that there is enough hardware to process 1080p images at 30fps. Is there any limitation of cv2.imshow with raspberry?

my code:

from picamera import PiCamera
from picamera.array import PiRGBArray
from time import sleep
import cv2
import time

camera = PiCamera()
camera.resolution = (1280, 720)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(1280, 720))

for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
        image = frame.array
        cv2.imshow("Frame", image)
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):

any suggestion?