Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import numpy as np | |
| import cv2 | |
| import os | |
| from PIL import Image | |
| import matplotlib.pyplot as plt | |
| def depthMap(imgL,imgR): | |
| imgL = cv2.cvtColor(imgL, cv2.COLOR_RGB2GRAY) | |
| imgR = cv2.cvtColor(imgR, cv2.COLOR_RGB2GRAY) | |
| stereoMatcher = cv2.StereoBM_create() | |
| stereoMatcher.setMinDisparity(4) | |
| stereoMatcher.setNumDisparities(128) | |
| stereoMatcher.setBlockSize(21) | |
| stereoMatcher.setSpeckleRange(16) | |
| stereoMatcher.setSpeckleWindowSize(45) | |
| disparity = stereoMatcher.compute(imgL,imgR) | |
| gray = plt.get_cmap('gray') | |
| disparity = disparity - np.min(disparity) | |
| disparity = disparity / np.max(disparity) | |
| disparity = gray(disparity)[:, :, :3] | |
| return disparity | |
| leftCam = gr.inputs.Image(type="numpy") | |
| RightCam = gr.inputs.Image(type="numpy") | |
| map = gr.Interface(fn=depthMap, | |
| inputs=[leftCam,RightCam], | |
| outputs="image").launch(debug=True), |