Try stuff
This commit is contained in:
@@ -40,11 +40,25 @@ 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()
|
||||
fen = self.__get_fen(frame)
|
||||
return frame, fen
|
||||
result = self.__run_complete_detection(frame)
|
||||
|
||||
edges_prediction = result["edges"]
|
||||
pieces_prediction = result["pieces"]
|
||||
|
||||
processed_frame = self.board_manager.process_frame(edges_prediction[0], frame, self.scale_size)
|
||||
if processed_frame is None:
|
||||
return frame.tobytes(), None
|
||||
|
||||
warped_corners = processed_frame[0]
|
||||
matrix = processed_frame[1]
|
||||
|
||||
detections = self.pieces_manager.extract_pieces(pieces_prediction)
|
||||
|
||||
board = self.pieces_manager.pieces_to_board(detections, warped_corners, matrix, self.scale_size)
|
||||
|
||||
return pieces_prediction[0].plot().tobytes(), 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)
|
||||
@@ -71,26 +85,6 @@ class DetectionService:
|
||||
self.__display_frame(prediction[0].plot())
|
||||
return prediction
|
||||
|
||||
|
||||
def __get_fen(self, frame : np.ndarray) -> str | None:
|
||||
result = self.__run_complete_detection(frame)
|
||||
|
||||
edges_prediction = result["edges"]
|
||||
pieces_prediction = result["pieces"]
|
||||
|
||||
processed_frame = self.board_manager.process_frame(edges_prediction[0], frame, self.scale_size)
|
||||
if processed_frame is None:
|
||||
return None
|
||||
|
||||
warped_corners = processed_frame[0]
|
||||
matrix = processed_frame[1]
|
||||
|
||||
detections = self.pieces_manager.extract_pieces(pieces_prediction)
|
||||
|
||||
board = self.pieces_manager.pieces_to_board(detections, warped_corners, matrix, self.scale_size)
|
||||
|
||||
return self.pieces_manager.board_to_fen(board)
|
||||
|
||||
def __display_frame(self, frame : np.ndarray):
|
||||
cv2.namedWindow("Frame", cv2.WINDOW_NORMAL)
|
||||
cv2.resizeWindow("Frame", self.scale_size[0], self.scale_size[1])
|
||||
|
||||
Reference in New Issue
Block a user