Beispiel #1
0
 def get_mask_type(mask_type, predicted_available):
     """ Return the requested mask type. Return default mask if
         predicted requested but not available """
     logger.debug("Requested mask_type: %s", mask_type)
     if mask_type == "predicted" and not predicted_available:
         mask_type = model_masks.get_default_mask()
         logger.warning("Predicted selected, but the model was not trained with a mask. "
                        "Switching to '%s'", mask_type)
     logger.debug("Returning mask_type: %s", mask_type)
     return mask_type
Beispiel #2
0
 def get_mask_type(mask_type, predicted_available):
     """ Return the requested mask type. Return default mask if
         predicted requested but not available """
     logger.debug("Requested mask_type: %s", mask_type)
     if mask_type == "predicted" and not predicted_available:
         mask_type = model_masks.get_default_mask()
         logger.warning("Predicted selected, but the model was not trained with a mask. "
                        "Switching to '%s'", mask_type)
     logger.debug("Returning mask_type: %s", mask_type)
     return mask_type
Beispiel #3
0
    def add_alpha_mask(self, frame, predicted):
        """ Adding a 4th channel should happen after all other channel operations
            Add the default mask as 4th channel for saving as png with alpha channel """
        if not self.draw_transparent:
            return frame
        logger.trace("Creating transparent image: '%s'", predicted["filename"])
        mask_type = getattr(model_masks, model_masks.get_default_mask())
        final_mask = np.zeros(frame.shape[:2] + (1, ), dtype="float32")

        for detected_face in predicted["detected_faces"]:
            landmarks = detected_face.landmarks_as_xy
            final_mask = cv2.bitwise_or(
                final_mask,  # pylint: disable=no-member
                mask_type(landmarks, frame, channels=1).mask)
        final_mask = np.expand_dims(
            final_mask, axis=-1) if final_mask.ndim == 2 else final_mask
        frame = np.concatenate((frame, final_mask), axis=-1)
        logger.trace("Created transparent image: '%s'", predicted["filename"])
        return frame