Args: im (str/np.ndarray): path of image/np.ndarray read by cv2 results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] MaskRCNN's results include 'masks'
(im, results, labels, threshold=0.5)
| 33 | |
| 34 | |
| 35 | def visualize_box_mask(im, results, labels, threshold=0.5): |
| 36 | """ |
| 37 | Args: |
| 38 | im (str/np.ndarray): path of image/np.ndarray read by cv2 |
| 39 | results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, |
| 40 | matix element:[class, score, x_min, y_min, x_max, y_max] |
| 41 | MaskRCNN's results include 'masks': np.ndarray: |
| 42 | shape:[N, im_h, im_w] |
| 43 | labels (list): labels:['class1', ..., 'classn'] |
| 44 | threshold (float): Threshold of score. |
| 45 | Returns: |
| 46 | im (PIL.Image.Image): visualized image |
| 47 | """ |
| 48 | if isinstance(im, str): |
| 49 | im = Image.open(im).convert('RGB') |
| 50 | elif isinstance(im, np.ndarray): |
| 51 | im = Image.fromarray(im) |
| 52 | if 'masks' in results and 'boxes' in results and len(results['boxes']) > 0: |
| 53 | im = draw_mask( |
| 54 | im, results['boxes'], results['masks'], labels, threshold=threshold) |
| 55 | if 'boxes' in results and len(results['boxes']) > 0: |
| 56 | im = draw_box(im, results['boxes'], labels, threshold=threshold) |
| 57 | if 'segm' in results: |
| 58 | im = draw_segm( |
| 59 | im, |
| 60 | results['segm'], |
| 61 | results['label'], |
| 62 | results['score'], |
| 63 | labels, |
| 64 | threshold=threshold) |
| 65 | return im |
| 66 | |
| 67 | |
| 68 | def get_color_map_list(num_classes): |
no test coverage detected