Преглед на файлове

fix: Expected RGB image of shape (?, ?, 3), but image.shape is (?, ?, 4).

goecho преди 3 години
родител
ревизия
fb3b9feb72
променени са 1 файла, в които са добавени 4 реда и са изтрити 0 реда
  1. 4 0
      rembg/bg.py

+ 4 - 0
rembg/bg.py

@@ -37,6 +37,10 @@ def alpha_matting_cutout(
     background_threshold: int,
     erode_structure_size: int,
 ) -> PILImage:
+
+    if img.mode == "RGBA" or img.mode == "CMYK":
+        img = img.convert("RGB")
+
     img = np.asarray(img)
     mask = np.asarray(mask)