omnimatte icon indicating copy to clipboard operation
omnimatte copied to clipboard

how use Detectron2 output Binary Mask image

Open 565ee opened this issue 3 years ago • 1 comments

o m

im = cv2.imread("./1.jpg")
cv2_imshow(im)

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 

cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
predictor = DefaultPredictor(cfg)
outputs = predictor(im)

v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
cv2_imshow(out.get_image()[:, :, ::-1])

565ee avatar Sep 29 '21 15:09 565ee

You can save the bottom image and use it as the input mask.

erikalu avatar Oct 29 '21 14:10 erikalu