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

Make segment overlay invisible #179

Open
Niutonian opened this issue Jan 22, 2024 · 0 comments
Open

Make segment overlay invisible #179

Niutonian opened this issue Jan 22, 2024 · 0 comments

Comments

@Niutonian
Copy link

Hello, I love pixellib,
I'm currently working on project that requires the background to be blacked out and the person to be in normal color,
my problem is that right now no matter what I try, there's always the segmentation overlay on top of my selection,
I have tried a few solution, but none work as well and as fast as the one below.

can anyone tell me how to make my overlay invisible

'''''import pixellib
from pixellib.torchbackend.instance import instanceSegmentation
import cv2
import numpy as np

capture = cv2.VideoCapture(0)

segment_video = instanceSegmentation()
segment_video.load_model("pointrend_resnet50.pkl", detection_speed="fast")
target_classes = segment_video.select_target_classes(person=True)

while capture.isOpened():
ret, frame = capture.read()
if not ret:
break

# Perform the segmentation
results = segment_video.segmentFrame(frame, show_bboxes=False, segment_target_classes=target_classes)

# The segmentation result is the first element in the results tuple
result = results[0]

# Extract the mask for the person class (assuming person class ID is 0)
masks = result['masks']
if masks.shape[2] > 0:
    person_mask = np.sum(masks, axis=2).astype(bool)

    # Use the original frame where the mask is True, and set the background to black
    frame = np.where(person_mask[:,:,None], frame, 1)

# Display the resulting frame
cv2.imshow('frame', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

capture.release()
cv2.destroyAllWindows()'''''

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant