Write depth map to pfm and png file. Args: path (str): filepath without extension depth (array): depth
(path, depth, bits=1)
| 62 | |
| 63 | |
| 64 | def write_depth(path, depth, bits=1): |
| 65 | """Write depth map to pfm and png file. |
| 66 | |
| 67 | Args: |
| 68 | path (str): filepath without extension |
| 69 | depth (array): depth |
| 70 | """ |
| 71 | write_pfm(path + ".pfm", depth.astype(np.float32)) |
| 72 | |
| 73 | depth_min = depth.min() |
| 74 | depth_max = depth.max() |
| 75 | |
| 76 | max_val = (2**(8 * bits)) - 1 |
| 77 | |
| 78 | if depth_max - depth_min > np.finfo("float").eps: |
| 79 | out = max_val * (depth - depth_min) / (depth_max - depth_min) |
| 80 | else: |
| 81 | out = np.zeros(depth.shape, dtype=depth.type) |
| 82 | |
| 83 | if bits == 1: |
| 84 | cv2.imwrite(path + ".png", out.astype("uint8")) |
| 85 | elif bits == 2: |
| 86 | cv2.imwrite(path + ".png", out.astype("uint16")) |
| 87 | return path + '.pfm', path + ".png" |
no test coverage detected