Spaces:
Runtime error
Runtime error
| import cv2 | |
| import numpy as np | |
| def visualize_pieces(image: np.ndarray, pieces: list) -> np.ndarray: | |
| vis_image = image.copy() | |
| for piece in pieces: | |
| contour = piece.get('contour') # Assume contour is stored | |
| if contour is not None: | |
| cv2.drawContours(vis_image, [contour], -1, (0, 255, 0), 2) | |
| cv2.putText( | |
| vis_image, | |
| f"ID: {piece['id']}", | |
| (int(contour[:, :, 0].min()), int(contour[:, :, 1].min()) - 10), | |
| cv2.FONT_HERSHEY_SIMPLEX, | |
| 0.5, | |
| (0, 0, 255), | |
| 1 | |
| ) | |
| return vis_image |