From 5c016b37fc39b29ede2fc08269d1add0cbc50fe2 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Mon, 8 May 2023 20:47:50 +0530 Subject: CamTest: Adding FPS --- CamTest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'CamTest.py') diff --git a/CamTest.py b/CamTest.py index cd3917e..1e0cc2a 100644 --- a/CamTest.py +++ b/CamTest.py @@ -1,20 +1,33 @@ import cv2 +import time from picamera2 import Picamera2 + # Create an instance of the PiCamera2 object cam = Picamera2() +#Parameters +fps=0 +pos=(30,60) #top-left +font=cv2.FONT_HERSHEY_COMPLEX +height=1.5 +color=(0,0,255) #BGR- RED +weight=3 # Set the resolution of the camera preview cam.preview_configuration.main.size = (640, 360) cam.preview_configuration.main.format = "RGB888" +cam.preview_configuration.controls.FrameRate=30 cam.preview_configuration.align() cam.configure("preview") cam.start() # While loop to continuously capture frames from camera while True: + tStart=time.time() # Capture a frame from the camera frame=cam.capture_array() + #Display FPS + cv2.putText(frame,str(int(fps))+' FPS',pos,font,height,color,weight) # Convert frame from BGR to grayscale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) @@ -31,6 +44,12 @@ while True: elif key == 113: # q key break + #calculate fps + tEnd=time.time() + # time between two epochs + looptime=tEnd-tStart + fps=1/looptime + # Release the camera and close all windows cam.stop() cv2.destroyAllWindows() -- cgit v1.2.3