Camera : viewfinder permanent + preview live pendant compte à rebours

- activer_viewfinder() à la connexion DSLR (miroir levé dès le démarrage)
- activer_viewfinder() après chaque capture (certains Canon le désactivent)
- Suppression desactiver_viewfinder() — miroir ne redescend plus jamais
- lancerPreview() au début du compte à rebours, arreterPreview() juste avant la capture
- Preview live fonctionnel : l'utilisateur se voit pendant tout le compte à rebours

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 22:32:46 +02:00
parent 0477831679
commit 0a918666b3
2 changed files with 10 additions and 20 deletions

View File

@@ -85,6 +85,7 @@ class Camera:
self.connectee = True self.connectee = True
self.mode = "gphoto2" self.mode = "gphoto2"
log.info("Camera DSLR connectee") log.info("Camera DSLR connectee")
self.activer_viewfinder()
return True return True
except gp.GPhoto2Error as e: except gp.GPhoto2Error as e:
log.warning(f"Pas de DSLR : {e}") log.warning(f"Pas de DSLR : {e}")
@@ -157,6 +158,7 @@ class Camera:
) )
tmp_path = str(chemin_dest) + ".tmp" tmp_path = str(chemin_dest) + ".tmp"
fichier_camera.save(tmp_path) fichier_camera.save(tmp_path)
self.activer_viewfinder() # Miroir relevé immédiatement après la prise
img = PILImage.open(tmp_path) img = PILImage.open(tmp_path)
if img.width > 4000: if img.width > 4000:
ratio = 4000 / img.width ratio = 4000 / img.width
@@ -199,31 +201,19 @@ class Camera:
return None # Pas de simulation ni webcam en dehors du mode dedie return None # Pas de simulation ni webcam en dehors du mode dedie
def activer_viewfinder(self): def activer_viewfinder(self):
"""Active le LiveView sur les Canon.""" """Active le LiveView (miroir levé en permanence) sur les Canon."""
if self.mode != "gphoto2" or not self.connectee: if self.mode != "gphoto2" or not self.connectee:
return return
try: try:
cfg = self.camera.get_config() with self._gp_lock:
vf = cfg.get_child_by_name("viewfinder") cfg = self.camera.get_config()
vf.set_value(1) vf = cfg.get_child_by_name("viewfinder")
self.camera.set_config(cfg) vf.set_value(1)
self.camera.set_config(cfg)
log.info("Viewfinder activé") log.info("Viewfinder activé")
except Exception as e: except Exception as e:
log.warning(f"Viewfinder non supporté : {e}") log.warning(f"Viewfinder non supporté : {e}")
def desactiver_viewfinder(self):
"""Désactive le LiveView."""
if self.mode != "gphoto2" or not self.connectee:
return
try:
cfg = self.camera.get_config()
vf = cfg.get_child_by_name("viewfinder")
vf.set_value(0)
self.camera.set_config(cfg)
log.info("Viewfinder désactivé")
except Exception as e:
log.warning(f"Viewfinder non supporté : {e}")
def _preview_gphoto2(self) -> bytes | None: def _preview_gphoto2(self) -> bytes | None:
try: try:
fichier = self.camera.capture_preview() fichier = self.camera.capture_preview()

View File

@@ -111,12 +111,12 @@ async function lancerCapture() {
compteurEl.textContent = `Photo ${i + 1} / ${nbPhotos}`; compteurEl.textContent = `Photo ${i + 1} / ${nbPhotos}`;
} }
// Compte a rebours SANS preview (libere la camera) lancerPreview(); // Miroir live pendant le compte à rebours
await compteARebours(); await compteARebours();
arreterPreview(); // Libère le bus USB gphoto2 pour la capture
afficherFlash(); afficherFlash();
// Preview arrete -> capture propre sans conflit gphoto2
const promesseCapture = apiPost('/api/capturer').catch(() => null); const promesseCapture = apiPost('/api/capturer').catch(() => null);
let resultat = await promesseCapture; let resultat = await promesseCapture;
let erreurReseau = false; let erreurReseau = false;