From 4c9271612da0a83f9b09ec77f471a5a8e6c2f184 Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 22 Apr 2026 00:09:56 +0200 Subject: [PATCH] capture --- .../modules/capture_interface.py | 46 +------------------ test_tube_scanner/scanner/multiwell.py | 10 ++-- 2 files changed, 6 insertions(+), 50 deletions(-) diff --git a/test_tube_scanner/modules/capture_interface.py b/test_tube_scanner/modules/capture_interface.py index 1c71915..a976b71 100644 --- a/test_tube_scanner/modules/capture_interface.py +++ b/test_tube_scanner/modules/capture_interface.py @@ -80,48 +80,7 @@ class VideoCaptureInterface(abc.ABC): ) self._last_detection = None # résultat du dernier alignement - # calibrage ou lecture réelle - # - - def align_on_well_arrival(self, frame: bytes, cnc_controller, tube_diameter: float = 16.0) -> dict: - """ - Appelé UNE FOIS à l'arrivée sur un nouveau puits. - Détecte le tube, décide l'action, exécute la correction. - - :param frame: Frame JPEG bytes capturée après déplacement CNC - :param grbl_send_func: Callable(gcode: str) → envoie le G-code au GRBL - :return: dict résultat de la détection - """ - nparr = np.frombuffer(frame, np.uint8) - img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) - detection = self._aligner.detect_tube(img, tube_diameter=tube_diameter) - - # Stockage pour process_frame - self._last_detection = detection - - if not detection["detected"]: - logger.warning("align_on_well_arrival: tube non détecté") - return detection - - action = detection["action"] - if action == "grbl": - dx_mm = detection["offset_x_mm"] - dy_mm = detection["offset_y_mm"] - - msg = f"align_on_well_arrival: correction CNC move_relative(dx={dx_mm:.3f}, dy={dy_mm:.3f})" - cnc_controller.move_relative(dx=dx_mm, dy=dy_mm, feed=150) - - self._tracker.reset() - self._last_detection["action"] = "none" - - elif action == "crop": - msg = f"align_on_well_arrival: recadrage logiciel ({detection['offset_x_px']:.1f}px, {detection['offset_y_px']:.1f}px)" - - logger.info(msg) - self.display(state='detect_tube', msg=msg) - return detection - - + def on_well_change(self): """ Appelé par le CNC lors du changement de puits. @@ -280,9 +239,6 @@ class VideoCaptureInterface(abc.ABC): self._last_detection = self._aligner.detect_tube(frame, self.parent.data.tube_diameter or 16.0) annotated = self._last_detection.get('frame_annotated') frame = annotated if annotated is not None else frame - - #if (self._last_detection.get("action") == "crop" and self._last_detection.get("detected")): - # frame = self._aligner.crop_to_tube(frame, self._last_detection) # mode racking if self.use_tracking: diff --git a/test_tube_scanner/scanner/multiwell.py b/test_tube_scanner/scanner/multiwell.py index e1e7562..96e6733 100644 --- a/test_tube_scanner/scanner/multiwell.py +++ b/test_tube_scanner/scanner/multiwell.py @@ -7,8 +7,6 @@ Created on 20 avr. 2026 @author: denis ''' -import cv2 -import numpy as np import logging import time from threading import Thread, Event @@ -17,6 +15,8 @@ from django.utils import timezone from django.utils.html import mark_safe from . import models +CALIBRATION_AUTO_DURATION = 45.0 +CALIBRATION_AUTO_TIMEOUT = 3.0 logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -229,7 +229,7 @@ class MultiWellManager: self.stop_playing = Event() self.process.data.tube_diameter = self.multiwell.diameter cam = self.process.cam - duration = self.duration if not auto else 45.0 + duration = self.duration if not auto else CALIBRATION_AUTO_DURATION start_test = time.monotonic() for w in self.well_iterator: @@ -245,14 +245,14 @@ class MultiWellManager: break if auto and cam._last_detection: if cam._last_detection.get('action')=="grbl": - self.cnc_controller.wait_for(5.0) + self.cnc_controller.wait_for(CALIBRATION_AUTO_TIMEOUT) dx_mm = cam._last_detection["offset_x_mm"] dy_mm = cam._last_detection["offset_y_mm"] self.cnc_controller.move_to(self.cnc_controller.x + dx_mm, self.cnc_controller.y + dy_mm, feed=150) msg = f"Correction CNC move_relative(dx={dx_mm:.3f}, dy={dy_mm:.3f})" self.process._send(state='center', msg=msg) - elif cam._last_detection.get('action') in ['none', 'crop']: + elif cam._last_detection.get('action') in ['none',]: msg = f"ok {w.multiwell.position}-{w.well.name}: ({self.cnc_controller.x}, {self.cnc_controller.y})" logger.info(msg) self.process._send(state='save', msg=msg)