codic commited on
Commit
3984d08
·
verified ·
1 Parent(s): ef93317

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -1
app.py CHANGED
@@ -9,7 +9,6 @@ import os
9
 
10
  feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
11
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
12
-
13
  def process_image(image_path, depth_map_path=None):
14
  image_path = Path(image_path)
15
  image_raw = Image.open(image_path)
@@ -23,6 +22,9 @@ def process_image(image_path, depth_map_path=None):
23
  depth_image_raw = Image.open(depth_map_path)
24
  depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
25
  depth_image = np.array(depth_image)
 
 
 
26
  else:
27
  # Automatically generate the depth map using the model
28
  encoding = feature_extractor(image, return_tensors="pt")
 
9
 
10
  feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
11
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
 
12
  def process_image(image_path, depth_map_path=None):
13
  image_path = Path(image_path)
14
  image_raw = Image.open(image_path)
 
22
  depth_image_raw = Image.open(depth_map_path)
23
  depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
24
  depth_image = np.array(depth_image)
25
+
26
+ # Invert the depth map if needed (for MiDaS depth maps)
27
+ depth_image = np.max(depth_image) - depth_image
28
  else:
29
  # Automatically generate the depth map using the model
30
  encoding = feature_extractor(image, return_tensors="pt")