diff --git a/ocv_rpicam.py b/ocv_rpicam.py index cfc1277..01f78d5 100755 --- a/ocv_rpicam.py +++ b/ocv_rpicam.py @@ -38,6 +38,8 @@ picam2 = Picamera2() pprint(picam2.sensor_modes) settings = {'NoiseReductionMode': 0, 'AeExposureMode': 0, 'ExposureTime': 10000, 'AnalogueGain': 1, 'FrameRate': picam2.sensor_modes[0]['fps']} caps = {"FrameRate": (1, picam2.sensor_modes[0]['fps'], None)} +timer = None + def load_settings(): _result = None @@ -76,14 +78,25 @@ def get_value(item: str): return picam2.camera_controls[item] def process(request): - colour = (0, 255, 0) - origin = (0, 30) - font = cv2.FONT_HERSHEY_SIMPLEX - scale = 1 - thickness = 2 + global timer + fps = 0 + timestamp = time.strftime("%Y-%m-%d %X") + + # Calculate Frames per second (FPS) + if timer is not None: + fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer) + + with MappedArray(request, "main") as m: - cv2.putText(m.array, timestamp, origin, font, scale, colour, thickness) + # Display timestamp on frame + cv2.putText(m.array, timestamp, (0, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) + + # Display FPS on frame + cv2.putText(m.array, "FPS : " + str(int(fps)), (20, m.array.shape[0] - 20), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 240, 0), 2) + + # Start timer + timer = cv2.getTickCount() if __name__ == '__main__': for item in items: diff --git a/settings.json b/settings.json index 17fabfb..0abe1bc 100755 --- a/settings.json +++ b/settings.json @@ -1,7 +1,7 @@ { "NoiseReductionMode": 0, "AeExposureMode": 0, -"ExposureTime": 19029, -"AnalogueGain": 1, -"FrameRate": 25.000000000000007 +"ExposureTime": 12829, +"AnalogueGain": 5.0, +"FrameRate": 10.380000000000003 } \ No newline at end of file