Closed Striker2k closed 4 months ago
Code :
import rembg import cv2 from PIL import Image
def remove_background(image_path, output_path): input_image = cv2.imread(image_path) input_image_rgb = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB) output_image = rembg. remove(input_image_rgb) output_image_gray = cv2.cvtColor(output_image, cv2.COLORRGB2GRAY" contours, = cv2.findContours(output_image_gray, cv2.RETR_EXTERNAL, cV2.CHAIN_APPROX_SIMPLE)
if len(contours) > 0:
largest_contour = max(contours, key=cv2.contourArea)
x, y, w, h = cv2.boundingRect(largest_contour)
x1, y1, x2, y2 = x, y, x+w, y+h
cropped_output_image = output_image[y1:y2, x1:x2]
cropped_output_image_pil = Image.fromarray(cropped_output_image)
cropped_output_image_pil.save(output_path)
return output_path
else:
print("Error: No foreground detected.")
return None
image_path = "Media.jpeg" output_path = "error.png" remove_background(image_path, output_path)
Error.png / output
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Any update regarding this?
Describe the bug 1] When user is using id card, rembg is unable to crop inage
To Reproduce Steps to reproduce the behavior:
Expected behavior Image should remove background properly.
Images Input images to reproduce.
OS Version: Android Version 12
Rembg version: v2.0.54