def draw_polygons(image: np.ndarray, polygons: Polygons, thickness=2): canvas = image.copy().astype(np.uint8) num = len(polygons) if num == 0: return canvas for idx in range(num): item_dict = polygons.get(idx) points = item_dict['contour'].astype(np.int32) if polygons.has_field('training_tag'): if not item_dict['fields']['training_tag']: lines_color = COLORS[-1] if not polygons.has_field('training_tag') or item_dict['fields']['training_tag']: lines_color = COLORS[0] for i in range(len(points)): cv2.line(canvas, (points[i][0], points[i][1]), (points[i-1][0], points[i-1][1]), lines_color[0], thickness) return canvas
def test_has_field(self): contours = [np.zeros([4, 2]), np.zeros([4, 2]), np.zeros([4, 2])] polygons = Polygons(contours) self.assertTrue(polygons.has_field('num_points')) self.assertFalse(polygons.has_field('abc'))