File size: 890 Bytes
839654a
 
 
df45565
beed0b6
0612f0e
839654a
 
1f68bc7
 
839654a
 
2cd58e7
839654a
 
 
 
0612f0e
 
 
 
6da63eb
839654a
bcc5aae
 
839654a
 
 
0ed850c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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),