Finally
This commit is contained in:
@@ -40,8 +40,10 @@ class DetectionService:
|
||||
def stop(self):
|
||||
self.camera.close()
|
||||
|
||||
def analyze_single_frame(self) -> tuple[np.ndarray, str | None]:
|
||||
def analyze_single_frame(self) -> tuple[bytes, str | None]:
|
||||
frame = self.camera.take_photo()
|
||||
encoded_frame = cv2.imencode('.jpg', frame, [int(cv2.IMWRITE_JPEG_QUALITY), 80])[1].tobytes()
|
||||
|
||||
result = self.__run_complete_detection(frame)
|
||||
|
||||
edges_prediction = result["edges"]
|
||||
@@ -49,7 +51,7 @@ class DetectionService:
|
||||
|
||||
processed_frame = self.board_manager.process_frame(edges_prediction[0], frame, self.scale_size)
|
||||
if processed_frame is None:
|
||||
return frame, None
|
||||
return encoded_frame, None
|
||||
|
||||
warped_corners, matrix = processed_frame
|
||||
|
||||
@@ -57,7 +59,7 @@ class DetectionService:
|
||||
|
||||
board = self.pieces_manager.pieces_to_board(detections, warped_corners, matrix, self.scale_size)
|
||||
|
||||
return pieces_prediction[0].plot(), self.pieces_manager.board_to_fen(board)
|
||||
return encoded_frame, 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)
|
||||
|
||||
@@ -23,5 +23,5 @@ class GameService:
|
||||
self.clock_service.stop()
|
||||
self.detection_service.stop()
|
||||
|
||||
def make_move(self) -> tuple[np.ndarray, str]:
|
||||
def make_move(self) -> tuple[bytes, str]:
|
||||
return self.detection_service.analyze_single_frame()
|
||||
Reference in New Issue
Block a user