(segmentation, image_in, seg_color_ref, image_scale=0.5)
| 80 | return sweep |
| 81 | |
| 82 | def get_semantic_image(segmentation, image_in, seg_color_ref, image_scale=0.5): |
| 83 | # Resize the image to reduce the memory overhead |
| 84 | network_image_shape = (1920 // 2, 1440 // 2) |
| 85 | if image_scale < 1: |
| 86 | # width = int(image_in.shape[1] * image_scale) |
| 87 | # height = int(image_in.shape[0] * image_scale) |
| 88 | # dim = (width, height) |
| 89 | dim = network_image_shape |
| 90 | image_in_resized = cv2.resize(image_in, dim, interpolation=cv2.INTER_AREA) |
| 91 | else: |
| 92 | image_in_resized = image_in |
| 93 | |
| 94 | # breakpoint() |
| 95 | ## ========== semantic segmentation |
| 96 | image_in_resized = segmentation.preprocess(image_in_resized) |
| 97 | image_out_resized = segmentation.segmentation(image_in_resized) |
| 98 | # breakpoint() |
| 99 | image_out_resized = np.reshape(image_out_resized, (1, 1440 // 2, 1920 // 2)) |
| 100 | image_out = image_out_resized.astype(np.uint8).squeeze() |
| 101 | |
| 102 | ## ========== Visualize semantic images |
| 103 | # Convert network label to color |
| 104 | colored_output = mapillary_visl.apply_color_map(image_out, seg_color_ref) |
| 105 | colored_output = np.squeeze(colored_output) |
| 106 | image_colored = colored_output.astype(np.uint8) |
| 107 | |
| 108 | if image_scale != 1.0: |
| 109 | new_shape = (image_in.shape[1], image_in.shape[0]) |
| 110 | # NOTE: we use INTER_NEAREST because values are discrete labels |
| 111 | image_colored = cv2.resize(image_colored, new_shape, |
| 112 | interpolation=cv2.INTER_NEAREST) |
| 113 | |
| 114 | return image_colored |
| 115 | |
| 116 | def get_semantic_image_path(image_path): |
| 117 | if "train" in str(image_path): |
no test coverage detected