Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ...improper removal of background #617

Closed
Striker2k opened this issue Apr 1, 2024 · 4 comments
Closed

[BUG] ...improper removal of background #617

Striker2k opened this issue Apr 1, 2024 · 4 comments
Labels
bug Something isn't working stale

Comments

@Striker2k
Copy link

Describe the bug
1] When user is using id card, rembg is unable to crop inage

To Reproduce
Steps to reproduce the behavior:

  1. Give model image of person with id card
  2. make sure that the background is bright

Expected behavior
Image should remove background properly.

Images
Input images to reproduce.
IMG-20240401-WA0004
IMG-20240401-WA0005

OS Version:
Android Version 12

Rembg version:
v2.0.54

@Striker2k Striker2k added the bug Something isn't working label Apr 1, 2024
@Striker2k
Copy link
Author

Striker2k commented Apr 2, 2024

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.COLOR_RGB2GRAY"
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 20240402_125300.jpg

Copy link

github-actions bot commented May 3, 2024

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label May 3, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

@Striker2k
Copy link
Author

Any update regarding this?

@Striker2k Striker2k changed the title [BUG] ...improper removal of background [BUG] ...improper removal of background May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

1 participant