Fix caméra : gvfsd-gphoto2, race condition viewfinder, exif_transpose

- kiosk-session.sh : tue gvfsd-gphoto2 au démarrage (démon GNOME qui
  monopolisait le DSLR sur USB et bloquait gphoto2)
- camera.py : viewfinder activé AVANT mode="gphoto2" → le thread preview
  ne peut plus appeler capture_preview() avant que LiveView soit prêt
- _activer_viewfinder_init() sans lock pour l'init (thread pas encore actif)
- exif_transpose sur les captures DSLR → corrige l'orientation et les
  bandes blanches dues aux photos mal orientées

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 17:33:31 +02:00
parent 0b4c5f9430
commit d3a71a9866
2 changed files with 22 additions and 4 deletions

View File

@@ -82,10 +82,11 @@ class Camera:
try:
self.camera = gp.Camera()
self.camera.init()
# Viewfinder activé AVANT de rendre la caméra visible au thread preview
self._activer_viewfinder_init()
self.connectee = True
self.mode = "gphoto2"
log.info("Camera DSLR connectee")
self.activer_viewfinder()
log.info("Camera DSLR connectee (LiveView actif)")
return True
except gp.GPhoto2Error as e:
log.warning(f"Pas de DSLR : {e}")
@@ -159,7 +160,8 @@ class Camera:
tmp_path = str(chemin_dest) + ".tmp"
fichier_camera.save(tmp_path)
self.activer_viewfinder() # Miroir relevé immédiatement après la prise
img = PILImage.open(tmp_path)
from PIL import ImageOps as PILImageOps
img = PILImageOps.exif_transpose(PILImage.open(tmp_path))
if img.width > 4000:
ratio = 4000 / img.width
img = img.resize((4000, int(img.height * ratio)), PILImage.LANCZOS)
@@ -200,8 +202,19 @@ class Camera:
else:
return None # Pas de simulation ni webcam en dehors du mode dedie
def _activer_viewfinder_init(self):
"""Active le LiveView pendant l'init (pas de lock, appelé avant que le thread démarre)."""
try:
cfg = self.camera.get_config()
vf = cfg.get_child_by_name("viewfinder")
vf.set_value(1)
self.camera.set_config(cfg)
log.info("Viewfinder activé (init)")
except Exception as e:
log.warning(f"Viewfinder non supporté : {e}")
def activer_viewfinder(self):
"""Active le LiveView (miroir levé en permanence) sur les Canon."""
"""Active le LiveView (miroir levé) depuis le thread — thread-safe."""
if self.mode != "gphoto2" or not self.connectee:
return
try: