I am trying to process frames from my V2 RPI Camera at high framerates and am stuck with the picamera module. The VideoCapture class from OpenCV seems to be much faster than using PiCamera.capture_continuous(). Here are my two different test codes:
from picamera import PiCamera from picamera.array import PiRGBArray import time import cv2 * PiCamera *
camera = PiCamera(framerate = 40) time.sleep(2) camera.resolution = (640,480) rawCapture = PiRGBArray(camera, size=camera.resolution) start = time.time() for frame, i in zip(camera.capture_continuous(rawCapture, format="bgr", use_video_port=True), range(400)): image = frame.array rawCapture.truncate(0) print("Time for {0} frames: {1} seconds".format(frames ,time.time()-start)) * OpenCV *
cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FRAME_WIDTH,640) cap.set(cv2.CAP_PROP_FRAME_HEIGHT,480) cap.set(cv2.CAP_PROP_FPS, 40) start = time.time() for i in range(400): ret, img = cap.read() print("Time for {0} frames: {1} seconds".format(frames, time.time() - start)) The outpus are:
Time for 400 frames: 25.839843720129837403 seconds Time for 400 frames: 10.234732929110973438 seconds Why is OpenCV so much faster? I would prefer to use picamera but I cannot get it to perform as expected. Thanks!