Datasets:
About disparity map to depth and point cloud conversion.
Can someone provide a script to convert a map to a depth map and point cloud? I've been working on it for a long time, and the resulting depth map and point cloud don't look quite right. Looking at the point cloud, the objects in the foreground are about one meter away, which seems reasonable, but the background walls are 13-18 meters high, which seems illogical.
Below is my script:
def readDispFSD(filename):
scale = 1000
disp = imageio.imread(filename)
disp = disp.astype(float)
out = disp[...,0]255255 + disp[...,1]*255 + disp[...,2]
out = out / float(scale)
valid = out > 0.0
return out, valid
def disp_to_depth(disp):
valid = disp > 0.2
depth = np.zeros_like(disp, dtype=np.float32)
depth[valid] = fx * baseline / disp[valid]
print(disp[valid].min(), disp[valid].max())
if save_in_mm:
depth = depth * 1000.0
return depth
disp, valid = readDispFSD(disp_path)
depth = disp_to_depth(disp)
For saving
name = os.path.splitext(os.path.basename(disp_path))[0]
save_path = os.path.join(save_dir, name + ".png")
depth_to_save = depth.astype(np.uint16)
Image.fromarray(depth_to_save).save(save_path)