From 29e6b185348acba217c098efe8bdc43e5d296719 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 31 Dec 2025 14:26:20 +0100 Subject: [PATCH] Im going crazy --- rpi/main.py | 1 + rpi/services/detection_service.py | 9 ++++----- rpi/services/game_service.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rpi/main.py b/rpi/main.py index bee077b4..8fee8bd2 100644 --- a/rpi/main.py +++ b/rpi/main.py @@ -65,6 +65,7 @@ def start_party(): def make_move(): try: frame, fen = game_service.make_move() + encoded_frame = cv2.imencode('.jpg', frame, [int(cv2.IMWRITE_JPEG_QUALITY), 80]) print(fen) headers = {'Content-Type': 'image/jpeg'} diff --git a/rpi/services/detection_service.py b/rpi/services/detection_service.py index eda6bdfe..7c1829a8 100644 --- a/rpi/services/detection_service.py +++ b/rpi/services/detection_service.py @@ -40,7 +40,7 @@ class DetectionService: def stop(self): self.camera.close() - def analyze_single_frame(self) -> tuple[bytes, str | None]: + def analyze_single_frame(self) -> tuple[np.ndarray, str | None]: frame = self.camera.take_photo() result = self.__run_complete_detection(frame) @@ -49,16 +49,15 @@ class DetectionService: processed_frame = self.board_manager.process_frame(edges_prediction[0], frame, self.scale_size) if processed_frame is None: - return frame.tobytes(), None + return frame, None - warped_corners = processed_frame[0] - matrix = processed_frame[1] + warped_corners, matrix = processed_frame detections = self.pieces_manager.extract_pieces(pieces_prediction) board = self.pieces_manager.pieces_to_board(detections, warped_corners, matrix, self.scale_size) - return cv2.imencode(".jpg", pieces_prediction[0].plot())[1].tobytes(), self.pieces_manager.board_to_fen(board) + return pieces_prediction[0].plot(), self.pieces_manager.board_to_fen(board) def __run_complete_detection(self, frame : np.ndarray, display=False) -> dict[str, list[Results]] : pieces_prediction = self.__run_pieces_detection(frame) diff --git a/rpi/services/game_service.py b/rpi/services/game_service.py index 524cf9ce..7848c8af 100644 --- a/rpi/services/game_service.py +++ b/rpi/services/game_service.py @@ -23,5 +23,5 @@ class GameService: self.clock_service.stop() self.detection_service.stop() - def make_move(self) -> tuple[bytes, str]: + def make_move(self) -> tuple[np.ndarray, str]: return self.detection_service.analyze_single_frame() \ No newline at end of file