facebookresearch / detectron2

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
https://detectron2.readthedocs.io/en/latest/
Apache License 2.0
30.41k stars 7.47k forks source link

How to get the visualization results of only instance masks without the original image? #4488

Open aihcyllop opened 2 years ago

aihcyllop commented 2 years ago

How to get the visualization results of only instance masks without the original image?

When I used demo to save the images of inference, it usually shows the instance segmentation results on original images.

I want to ask how to get only instance segmentation results without original images.

Thanks!

github-actions[bot] commented 2 years ago

You've chosen to report an unexpected problem or bug. Unless you already know the root cause of it, please include details about it by filling the issue template. The following information is missing: "Instructions To Reproduce the Issue and Full Logs"; "Your Environment";

frozen-mind commented 2 years ago

like get such kind of image? 1660814920165 here is the original image with mask: b1f0138f12ae9a1f4f76abe13074646

aihcyllop commented 2 years ago

@frozen-mind yes

frozen-mind commented 2 years ago

actually your answer is in the second tutorial vedio, here is the link https://www.youtube.com/watch?v=eUSgtfK4ivk starts from appoximately 17:00, the youtuber will show you how to get the mask of the image have fun ^ ^

aihcyllop commented 2 years ago

@frozen-mind Thank you!!

frozen-mind commented 2 years ago

btw, did you solve the problem in #4487 ?

aihcyllop commented 2 years ago

@frozen-mind sorry, I didn't faced the problem of $4487

frozen-mind commented 2 years ago

Lol fine

---Original--- From: @.> Date: Thu, Aug 18, 2022 18:08 PM To: @.>; Cc: @.**@.>; Subject: Re: [facebookresearch/detectron2] How to get the visualizationresults of only instance masks without the original image? (Issue #4488)

@frozen-mind sorry, I didn't faced the problem of $4487

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

owardlaw commented 2 years ago

You can loop through each canny like this and see each detection. I used something like this to manipulate the pixels of each detection.

# Load your image here and call predictor on it
frame = cv2.imread("test.png")
outputs = predictor(frame)
instances = outputs['instances']

# Referencing pred mask outputs
mask_array = instances.pred_masks.to("cpu").numpy()
mask_array = np.moveaxis(mask_array, 0, -1)
img = np.zeros_like(frame)
h = img.shape[0]
w = img.shape[1]
img_mask = np.zeros([h, w, 3], np.uint8)

# Looping through each detection
for i in range(instances):

    # Creat blank array matching image size and add single canny to array
    mask_array_instance = mask_array[:, :, i:(i+1)]
    applied_canny = np.where(mask_array_instance == True, 255, img)
    array_img = np.asarray(applied_canny)

    # Show Canny
    cv2.imshow('area', array_img)
    cv2.waitKey(0)