How do I save a mask as PNG whenever there is a detection in a video using the YOLACT model?

  deep-learning, image-segmentation, python, python-3.x, yolo

I am using the YOLACT instance segmentation model for one of my projects and I need to save just the masks that are being detected in a video. I am looking to capture and save the image that is inside the mask in a folder for every second. I have tried all kinds of Permutations and Combinations of code pipelines to work it out but in vain. So, can someone please help me out with this?

Source: Python-3x Questions