Preview DSLR : resize 960px + base64 hors asyncio pour fluidifier liveview

This commit is contained in:
2026-04-09 01:36:20 +02:00
parent 8e7fb61e90
commit 94e3d68dd7
2 changed files with 15 additions and 3 deletions

View File

@@ -200,8 +200,19 @@ class Camera:
def _preview_gphoto2(self) -> bytes | None:
try:
fichier = self.camera.capture_preview()
donnees = fichier.get_data_and_size()
return bytes(donnees)
donnees = bytes(fichier.get_data_and_size())
# Redimensionner pour alléger le WebSocket
img = cv2.imdecode(
__import__("numpy").frombuffer(donnees, dtype=__import__("numpy").uint8),
cv2.IMREAD_COLOR,
)
if img is not None:
h, w = img.shape[:2]
if w > 960:
img = cv2.resize(img, (960, int(h * 960 / w)), interpolation=cv2.INTER_LINEAR)
_, buf = cv2.imencode(".jpg", img, [cv2.IMWRITE_JPEG_QUALITY, 75])
return buf.tobytes()
return donnees
except gp.GPhoto2Error as e:
log.error(f"Erreur preview DSLR : {e}")
return None