|
|
|
@ -33,10 +33,10 @@ def inference(left, right, model, n_iter=20): |
|
|
|
|
align_corners=True, |
|
|
|
|
) |
|
|
|
|
# print(imgR_dw2.shape) |
|
|
|
|
with torch.inference_mode(): |
|
|
|
|
pred_flow_dw2 = model(imgL_dw2, imgR_dw2, iters=n_iter, flow_init=None) |
|
|
|
|
|
|
|
|
|
pred_flow_dw2 = model(imgL_dw2, imgR_dw2, iters=n_iter, flow_init=None) |
|
|
|
|
|
|
|
|
|
pred_flow = model(imgL, imgR, iters=n_iter, flow_init=pred_flow_dw2) |
|
|
|
|
pred_flow = model(imgL, imgR, iters=n_iter, flow_init=pred_flow_dw2) |
|
|
|
|
pred_disp = torch.squeeze(pred_flow[:, 0, :, :]).cpu().detach().numpy() |
|
|
|
|
|
|
|
|
|
return pred_disp |
|
|
|
@ -49,7 +49,7 @@ if __name__ == '__main__': |
|
|
|
|
in_h, in_w = left_img.shape[:2] |
|
|
|
|
|
|
|
|
|
# Resize image in case the GPU memory overflows |
|
|
|
|
eval_h, eval_w = (1024//4,1536//4) |
|
|
|
|
eval_h, eval_w = (in_h,in_w) |
|
|
|
|
imgL = cv2.resize(left_img, (eval_w, eval_h), interpolation=cv2.INTER_LINEAR) |
|
|
|
|
imgR = cv2.resize(right_img, (eval_w, eval_h), interpolation=cv2.INTER_LINEAR) |
|
|
|
|
|
|
|
|
@ -65,11 +65,12 @@ if __name__ == '__main__': |
|
|
|
|
t = float(in_w) / float(eval_w) |
|
|
|
|
disp = cv2.resize(pred, (in_w, in_h), interpolation=cv2.INTER_LINEAR) * t |
|
|
|
|
|
|
|
|
|
disp_vis = (disp - disp.min()) / (256 - disp.min()) * 255.0 |
|
|
|
|
disp_vis = (disp - disp.min()) / (disp.max() - disp.min()) * 255.0 |
|
|
|
|
disp_vis = disp_vis.astype("uint8") |
|
|
|
|
disp_vis = cv2.applyColorMap(disp_vis, cv2.COLORMAP_INFERNO) |
|
|
|
|
|
|
|
|
|
combined_img = np.hstack((left_img, disp_vis)) |
|
|
|
|
cv2.namedWindow("output", cv2.WINDOW_NORMAL) |
|
|
|
|
cv2.imshow("output", combined_img) |
|
|
|
|
cv2.imwrite("output.jpg", disp_vis) |
|
|
|
|
cv2.waitKey(0) |
|
|
|
|