1.1.3
Browse files
app.py
CHANGED
|
@@ -53,7 +53,7 @@ class DepthEstimator:
|
|
| 53 |
def estimate_depth(self, image_path):
|
| 54 |
try:
|
| 55 |
# Load image
|
| 56 |
-
|
| 57 |
|
| 58 |
# Resize image for processing
|
| 59 |
resized_image, new_size = self.resize_image(image_path)
|
|
@@ -118,9 +118,11 @@ def find_bottommost_footpath_pixel(mask, topmost_pixel):
|
|
| 118 |
top_y, top_x = topmost_pixel
|
| 119 |
|
| 120 |
# Find all mask pixels in the same x-column as the topmost pixel
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
if len(
|
| 124 |
# If no pixels in the same column, find the bottommost pixel in the entire mask
|
| 125 |
footpath_pixels = np.where(mask > 0)
|
| 126 |
if len(footpath_pixels[0]) == 0:
|
|
@@ -132,7 +134,7 @@ def find_bottommost_footpath_pixel(mask, topmost_pixel):
|
|
| 132 |
return (max_y, bottom_x_coords[center_idx])
|
| 133 |
|
| 134 |
# Find the bottommost pixel in the same x-column
|
| 135 |
-
max_y_in_column = np.max(
|
| 136 |
return (max_y_in_column, top_x)
|
| 137 |
|
| 138 |
|
|
@@ -235,7 +237,9 @@ async def estimate_depth_endpoint(file: UploadFile = File(...), mask: UploadFile
|
|
| 235 |
resized_image = cv2.resize(image, new_size)
|
| 236 |
resized_mask = cv2.resize(mask, new_size)
|
| 237 |
|
| 238 |
-
|
|
|
|
|
|
|
| 239 |
|
| 240 |
# Find key pixels from the mask
|
| 241 |
topmost_pixel = find_topmost_pixel(resized_mask)
|
|
|
|
| 53 |
def estimate_depth(self, image_path):
|
| 54 |
try:
|
| 55 |
# Load image
|
| 56 |
+
image = Image.open(image_path)
|
| 57 |
|
| 58 |
# Resize image for processing
|
| 59 |
resized_image, new_size = self.resize_image(image_path)
|
|
|
|
| 118 |
top_y, top_x = topmost_pixel
|
| 119 |
|
| 120 |
# Find all mask pixels in the same x-column as the topmost pixel
|
| 121 |
+
mask_y_coords, mask_x_coords = np.where(mask > 0)
|
| 122 |
+
column_mask = mask_x_coords == top_x
|
| 123 |
+
column_y_coords = mask_y_coords[column_mask]
|
| 124 |
|
| 125 |
+
if len(column_y_coords) == 0:
|
| 126 |
# If no pixels in the same column, find the bottommost pixel in the entire mask
|
| 127 |
footpath_pixels = np.where(mask > 0)
|
| 128 |
if len(footpath_pixels[0]) == 0:
|
|
|
|
| 134 |
return (max_y, bottom_x_coords[center_idx])
|
| 135 |
|
| 136 |
# Find the bottommost pixel in the same x-column
|
| 137 |
+
max_y_in_column = np.max(column_y_coords)
|
| 138 |
return (max_y_in_column, top_x)
|
| 139 |
|
| 140 |
|
|
|
|
| 237 |
resized_image = cv2.resize(image, new_size)
|
| 238 |
resized_mask = cv2.resize(mask, new_size)
|
| 239 |
|
| 240 |
+
# Convert mask to grayscale if it's not already
|
| 241 |
+
if len(resized_mask.shape) == 3:
|
| 242 |
+
resized_mask = cv2.cvtColor(resized_mask, cv2.COLOR_BGR2GRAY)
|
| 243 |
|
| 244 |
# Find key pixels from the mask
|
| 245 |
topmost_pixel = find_topmost_pixel(resized_mask)
|