Resize image and make it fit for network. Args: img (array): image Returns: tensor: data ready for network
(img)
| 114 | |
| 115 | |
| 116 | def resize_image(img): |
| 117 | """Resize image and make it fit for network. |
| 118 | |
| 119 | Args: |
| 120 | img (array): image |
| 121 | |
| 122 | Returns: |
| 123 | tensor: data ready for network |
| 124 | """ |
| 125 | height_orig = img.shape[0] |
| 126 | width_orig = img.shape[1] |
| 127 | |
| 128 | if width_orig > height_orig: |
| 129 | scale = width_orig / 384 |
| 130 | else: |
| 131 | scale = height_orig / 384 |
| 132 | |
| 133 | # if width_orig > height_orig: |
| 134 | # scale = width_orig / 512 |
| 135 | # else: |
| 136 | # scale = height_orig / 512 |
| 137 | |
| 138 | height = (np.ceil(height_orig / scale / 32) * 32).astype(int) |
| 139 | width = (np.ceil(width_orig / scale / 32) * 32).astype(int) |
| 140 | |
| 141 | img_resized = cv2.resize(img, (width, height), interpolation=cv2.INTER_AREA) |
| 142 | |
| 143 | img_resized = ( |
| 144 | torch.from_numpy(np.transpose(img_resized, (2, 0, 1))).contiguous().float() |
| 145 | ) |
| 146 | img_resized = img_resized.unsqueeze(0) |
| 147 | |
| 148 | return img_resized |
| 149 | |
| 150 | |
| 151 | def resize_depth(depth, width, height): |
nothing calls this directly
no outgoing calls
no test coverage detected