Scripts test liveview : pygame, pyqt6, opencv, tkinter - mesure FPS et premiere image

This commit is contained in:
2026-04-09 12:42:50 +02:00
parent 19d1998704
commit a1a0ce0503
4 changed files with 257 additions and 0 deletions

48
scripts/test_opencv.py Normal file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env python3
"""Test liveview avec OpenCV. Lance: DISPLAY=:0 python3 scripts/test_opencv.py"""
import time
import io
import numpy as np
import cv2
import gphoto2 as gp
cam = gp.Camera()
cam.init()
print("Camera connectee")
t_start = time.time()
frame_count = 0
premier_frame = None
print("Appuie sur ESC pour quitter")
while True:
try:
t0 = time.time()
f = cam.capture_preview()
data = bytes(f.get_data_and_size())
dt = time.time() - t0
if premier_frame is None:
premier_frame = time.time() - t_start
print(f"1ere image en : {premier_frame:.2f}s")
arr = np.frombuffer(data, dtype=np.uint8)
img = cv2.imdecode(arr, cv2.IMREAD_COLOR)
img = cv2.resize(img, (960, 640))
frame_count += 1
fps = frame_count / (time.time() - t_start)
cv2.putText(img, f"FPS: {fps:.1f} frame: {dt*1000:.0f}ms", (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2)
cv2.imshow("Test liveview OpenCV", img)
if cv2.waitKey(1) & 0xFF == 27: # ESC
break
except Exception as e:
print(f"Erreur: {e}")
break
cam.exit()
cv2.destroyAllWindows()
print(f"Total: {frame_count} frames, {frame_count/(time.time()-t_start):.1f} FPS")