| 940 | return depth_map |
| 941 | |
| 942 | def read_MiDaS_depth(disp_fi, disp_rescale=10., h=None, w=None): |
| 943 | if 'npy' in os.path.splitext(disp_fi)[-1]: |
| 944 | disp = np.load(disp_fi) |
| 945 | else: |
| 946 | disp = imageio.imread(disp_fi).astype(np.float32) |
| 947 | disp = disp - disp.min() |
| 948 | disp = cv2.blur(disp / disp.max(), ksize=(3, 3)) * disp.max() |
| 949 | disp = (disp / disp.max()) * disp_rescale |
| 950 | if h is not None and w is not None: |
| 951 | disp = resize(disp / disp.max(), (h, w), order=1) * disp.max() |
| 952 | depth = 1. / np.maximum(disp, 0.05) |
| 953 | |
| 954 | return depth |
| 955 | |
| 956 | def follow_image_aspect_ratio(depth, image): |
| 957 | H, W = image.shape[:2] |