improved stability of FPS display

This commit is contained in:
2024-07-15 11:54:14 +02:00
parent 369ebacfef
commit f2342d04b5
2 changed files with 12 additions and 14 deletions
+9 -11
View File
@@ -38,7 +38,7 @@ 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
fps = 0
def load_settings():
@@ -78,16 +78,10 @@ def get_value(item: str):
return picam2.camera_controls[item]
def process(request):
global timer
fps = 0
global fps
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:
# Display timestamp on frame
cv2.putText(m.array, timestamp, (0, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
@@ -95,8 +89,6 @@ def process(request):
# 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:
@@ -126,6 +118,9 @@ if __name__ == '__main__':
picam2.start()
while True:
# Start timer
timer = cv2.getTickCount()
rgb = picam2.capture_array("main")
frame = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR)
@@ -193,7 +188,10 @@ if __name__ == '__main__':
fps = set_value('FrameRate', fps)
print(f"FPS: {fps}")
# Calculate Frames per second (FPS)
fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer)
# Release the capture and close windows
save_settings(settings)
cv2.destroyAllWindows()
+3 -3
View File
@@ -1,7 +1,7 @@
{
"NoiseReductionMode": 0,
"AeExposureMode": 0,
"ExposureTime": 12829,
"AnalogueGain": 5.0,
"FrameRate": 10.380000000000003
"ExposureTime": 13929,
"AnalogueGain": 1.0,
"FrameRate": 60.38
}