Advertisement
askanton

Як видалити фон зображення | Вивчаємо Python та бібліотеку #rembang

Oct 13th, 2022
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | Source Code | 0 0
  1. from rembg import remove
  2. from PIL import Image
  3. import cv2
  4.  
  5. source = "111.jpg"
  6. dest_pil = "222.png"
  7. dest_rembg = "333.png"
  8. dest_cv2 = "444.png"
  9. print("PIL")
  10. input = Image.open(source)
  11. output = remove(input)
  12. output.save(dest_pil)
  13. print("rembg")
  14. with open(source, 'rb') as i:
  15.     with open(dest_rembg, 'wb') as o:
  16.         input = i.read()
  17.         output = remove(input)
  18.         o.write(output)
  19. print("cv2")
  20. input = cv2.imread(source)
  21. output = remove(input)
  22. cv2.imwrite(dest_cv2, output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement