Spaces:
Running
on
Zero
Running
on
Zero
fixed setting of focal pixel distance
Browse files
app.py
CHANGED
|
@@ -116,13 +116,25 @@ def generate_3d_model(depth, image_path, focallength_px):
|
|
| 116 |
def predict_depth(input_image):
|
| 117 |
temp_file = None
|
| 118 |
try:
|
|
|
|
|
|
|
|
|
|
| 119 |
# Resize the input image to a manageable size
|
| 120 |
temp_file = resize_image(input_image)
|
|
|
|
| 121 |
|
| 122 |
# Preprocess the image for depth prediction
|
| 123 |
result = depth_pro.load_rgb(temp_file)
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
image = transform(image) # Apply preprocessing transforms
|
| 127 |
image = image.to(device) # Move the image tensor to the selected device
|
| 128 |
|
|
@@ -183,7 +195,10 @@ def predict_depth(input_image):
|
|
| 183 |
return output_path, f"Focal length: {focallength_px:.2f} pixels", raw_depth_path, view_model_path, download_model_path
|
| 184 |
except Exception as e:
|
| 185 |
# Return error messages in case of failures
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
| 187 |
finally:
|
| 188 |
# Clean up by removing the temporary resized image file
|
| 189 |
if temp_file and os.path.exists(temp_file):
|
|
|
|
| 116 |
def predict_depth(input_image):
|
| 117 |
temp_file = None
|
| 118 |
try:
|
| 119 |
+
print(f"Input image type: {type(input_image)}")
|
| 120 |
+
print(f"Input image path: {input_image}")
|
| 121 |
+
|
| 122 |
# Resize the input image to a manageable size
|
| 123 |
temp_file = resize_image(input_image)
|
| 124 |
+
print(f"Resized image path: {temp_file}")
|
| 125 |
|
| 126 |
# Preprocess the image for depth prediction
|
| 127 |
result = depth_pro.load_rgb(temp_file)
|
| 128 |
+
|
| 129 |
+
# Add error checking for the result tuple
|
| 130 |
+
if len(result) < 2:
|
| 131 |
+
raise ValueError(f"Unexpected result from load_rgb: {result}")
|
| 132 |
+
|
| 133 |
+
image = result[0] # Unpack the result tuple correctly
|
| 134 |
+
f_px = result[-1] # Extract focal length
|
| 135 |
+
|
| 136 |
+
print(f"Extracted focal length: {f_px}")
|
| 137 |
+
|
| 138 |
image = transform(image) # Apply preprocessing transforms
|
| 139 |
image = image.to(device) # Move the image tensor to the selected device
|
| 140 |
|
|
|
|
| 195 |
return output_path, f"Focal length: {focallength_px:.2f} pixels", raw_depth_path, view_model_path, download_model_path
|
| 196 |
except Exception as e:
|
| 197 |
# Return error messages in case of failures
|
| 198 |
+
import traceback
|
| 199 |
+
error_message = f"An error occurred: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
| 200 |
+
print(error_message) # Print the full error message to the console
|
| 201 |
+
return None, error_message, None, None, None
|
| 202 |
finally:
|
| 203 |
# Clean up by removing the temporary resized image file
|
| 204 |
if temp_file and os.path.exists(temp_file):
|