MCPcopy Create free account
hub / github.com/AgentMaker/PaddleQuickInference / write_depth

Function write_depth

examples/MiDaS/utils.py:64–87  ·  view source on GitHub ↗

Write depth map to pfm and png file. Args: path (str): filepath without extension depth (array): depth

(path, depth, bits=1)

Source from the content-addressed store, hash-verified

62
63
64def 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"

Callers 1

postprocessFunction · 0.90

Calls 1

write_pfmFunction · 0.85

Tested by

no test coverage detected