Daankular commited on
Commit
efcfdf3
·
1 Parent(s): 9757b8d

Patch find_bounding_box: guard empty contours (blank alpha fallback to full image bbox)

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -211,6 +211,21 @@ def load_triposg():
211
  _ip_path.write_text(_ip_text)
212
  print("[load_triposg] Patched image_process.py: rmbg_net None guard")
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  # Safety net: patch inference_utils.py to make diso import optional.
215
  # Even if diso compiled with submodules, guard against any residual link errors.
216
  _iu_path = triposg_src / "triposg" / "inference_utils.py"
 
211
  _ip_path.write_text(_ip_text)
212
  print("[load_triposg] Patched image_process.py: rmbg_net None guard")
213
 
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
+ if "empty_contours_guard" not in _ip_text:
218
+ _ip_text = _ip_path.read_text()
219
+ _ip_text = _ip_text.replace(
220
+ " max_contour = max(contours, key=cv2.contourArea)",
221
+ " if not contours: # empty_contours_guard\n"
222
+ " h, w = alpha.shape[:2]\n"
223
+ " return 0, 0, w, h\n"
224
+ " max_contour = max(contours, key=cv2.contourArea)",
225
+ )
226
+ _ip_path.write_text(_ip_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.
230
  # Even if diso compiled with submodules, guard against any residual link errors.
231
  _iu_path = triposg_src / "triposg" / "inference_utils.py"