Write depth map to pfm and png file. Args: path (str): filepath without extension depth (array): depth
(path, depth, bits=1)
| 163 | return depth_resized |
| 164 | |
| 165 | def write_depth(path, depth, bits=1): |
| 166 | """Write depth map to pfm and png file. |
| 167 | |
| 168 | Args: |
| 169 | path (str): filepath without extension |
| 170 | depth (array): depth |
| 171 | """ |
| 172 | write_pfm(path + ".pfm", depth.astype(np.float32)) |
| 173 | |
| 174 | depth_min = depth.min() |
| 175 | depth_max = depth.max() |
| 176 | |
| 177 | max_val = (2**(8*bits))-1 |
| 178 | |
| 179 | if depth_max - depth_min > np.finfo("float").eps: |
| 180 | out = max_val * (depth - depth_min) / (depth_max - depth_min) |
| 181 | else: |
| 182 | out = np.zeros(depth.shape, dtype=depth.type) |
| 183 | |
| 184 | if bits == 1: |
| 185 | cv2.imwrite(path + ".png", out.astype("uint8")) |
| 186 | elif bits == 2: |
| 187 | cv2.imwrite(path + ".png", out.astype("uint16")) |
| 188 | |
| 189 | return |
nothing calls this directly
no test coverage detected