Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,6 @@ import os
|
|
| 10 |
feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
| 11 |
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
| 12 |
|
| 13 |
-
|
| 14 |
def process_image(image_path, depth_map_path=None):
|
| 15 |
image_path = Path(image_path)
|
| 16 |
image_raw = Image.open(image_path)
|
|
@@ -20,8 +19,10 @@ def process_image(image_path, depth_map_path=None):
|
|
| 20 |
)
|
| 21 |
|
| 22 |
if depth_map_path:
|
| 23 |
-
# Load the user-provided depth map
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
else:
|
| 26 |
# Automatically generate the depth map using the model
|
| 27 |
encoding = feature_extractor(image, return_tensors="pt")
|
|
|
|
| 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)
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
if depth_map_path:
|
| 22 |
+
# Load and resize the user-provided depth map to match the RGB image size
|
| 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")
|