Spaces:
Running on Zero
Running on Zero
Fix empty_contours_guard patch: use gray_image (correct param name) not alpha
Browse files
app.py
CHANGED
|
@@ -214,16 +214,17 @@ def load_triposg():
|
|
| 214 |
# Patch find_bounding_box: guard against empty contours (blank alpha mask).
|
| 215 |
# When RMBG produces an all-black mask, findContours returns [] and max() raises.
|
| 216 |
# Fallback: return the full image bounding box so pipeline can continue.
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
| 220 |
" max_contour = max(contours, key=cv2.contourArea)",
|
| 221 |
" if not contours: # empty_contours_guard\n"
|
| 222 |
-
" h, w =
|
| 223 |
" return 0, 0, w, h\n"
|
| 224 |
" max_contour = max(contours, key=cv2.contourArea)",
|
| 225 |
)
|
| 226 |
-
_ip_path.write_text(
|
| 227 |
print("[load_triposg] Patched image_process.py: empty contours guard")
|
| 228 |
|
| 229 |
# Safety net: patch inference_utils.py to make diso import optional.
|
|
|
|
| 214 |
# Patch find_bounding_box: guard against empty contours (blank alpha mask).
|
| 215 |
# When RMBG produces an all-black mask, findContours returns [] and max() raises.
|
| 216 |
# Fallback: return the full image bounding box so pipeline can continue.
|
| 217 |
+
# NOTE: parameter is gray_image, not alpha.
|
| 218 |
+
_ip_text2 = _ip_path.read_text()
|
| 219 |
+
if "empty_contours_guard" not in _ip_text2:
|
| 220 |
+
_ip_text2 = _ip_text2.replace(
|
| 221 |
" max_contour = max(contours, key=cv2.contourArea)",
|
| 222 |
" if not contours: # empty_contours_guard\n"
|
| 223 |
+
" h, w = gray_image.shape[:2]\n"
|
| 224 |
" return 0, 0, w, h\n"
|
| 225 |
" max_contour = max(contours, key=cv2.contourArea)",
|
| 226 |
)
|
| 227 |
+
_ip_path.write_text(_ip_text2)
|
| 228 |
print("[load_triposg] Patched image_process.py: empty contours guard")
|
| 229 |
|
| 230 |
# Safety net: patch inference_utils.py to make diso import optional.
|