improved stability of FPS display
This commit is contained in:
+9
-11
@@ -38,7 +38,7 @@ picam2 = Picamera2()
|
|||||||
pprint(picam2.sensor_modes)
|
pprint(picam2.sensor_modes)
|
||||||
settings = {'NoiseReductionMode': 0, 'AeExposureMode': 0, 'ExposureTime': 10000, 'AnalogueGain': 1, 'FrameRate': picam2.sensor_modes[0]['fps']}
|
settings = {'NoiseReductionMode': 0, 'AeExposureMode': 0, 'ExposureTime': 10000, 'AnalogueGain': 1, 'FrameRate': picam2.sensor_modes[0]['fps']}
|
||||||
caps = {"FrameRate": (1, picam2.sensor_modes[0]['fps'], None)}
|
caps = {"FrameRate": (1, picam2.sensor_modes[0]['fps'], None)}
|
||||||
timer = None
|
fps = 0
|
||||||
|
|
||||||
|
|
||||||
def load_settings():
|
def load_settings():
|
||||||
@@ -78,16 +78,10 @@ def get_value(item: str):
|
|||||||
return picam2.camera_controls[item]
|
return picam2.camera_controls[item]
|
||||||
|
|
||||||
def process(request):
|
def process(request):
|
||||||
global timer
|
global fps
|
||||||
fps = 0
|
|
||||||
|
|
||||||
timestamp = time.strftime("%Y-%m-%d %X")
|
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:
|
with MappedArray(request, "main") as m:
|
||||||
# Display timestamp on frame
|
# Display timestamp on frame
|
||||||
cv2.putText(m.array, timestamp, (0, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
|
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
|
# 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)
|
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__':
|
if __name__ == '__main__':
|
||||||
for item in items:
|
for item in items:
|
||||||
@@ -126,6 +118,9 @@ if __name__ == '__main__':
|
|||||||
picam2.start()
|
picam2.start()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
# Start timer
|
||||||
|
timer = cv2.getTickCount()
|
||||||
|
|
||||||
rgb = picam2.capture_array("main")
|
rgb = picam2.capture_array("main")
|
||||||
frame = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR)
|
frame = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR)
|
||||||
|
|
||||||
@@ -193,7 +188,10 @@ if __name__ == '__main__':
|
|||||||
fps = set_value('FrameRate', fps)
|
fps = set_value('FrameRate', fps)
|
||||||
print(f"FPS: {fps}")
|
print(f"FPS: {fps}")
|
||||||
|
|
||||||
|
# Calculate Frames per second (FPS)
|
||||||
|
fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer)
|
||||||
|
|
||||||
|
|
||||||
# Release the capture and close windows
|
# Release the capture and close windows
|
||||||
save_settings(settings)
|
save_settings(settings)
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"NoiseReductionMode": 0,
|
"NoiseReductionMode": 0,
|
||||||
"AeExposureMode": 0,
|
"AeExposureMode": 0,
|
||||||
"ExposureTime": 12829,
|
"ExposureTime": 13929,
|
||||||
"AnalogueGain": 5.0,
|
"AnalogueGain": 1.0,
|
||||||
"FrameRate": 10.380000000000003
|
"FrameRate": 60.38
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user