How to use the mtcnn.exceptions.InvalidImage function in mtcnn

To help you get started, we’ve selected a few mtcnn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipazc / mtcnn / tests / test_mtcnn.py View on Github external
def test_detect_faces_invalid_content(self):
        """
        MTCNN detects invalid images
        :return:
        """
        ivan = cv2.imread("example.py")

        with self.assertRaises(InvalidImage):
            result = mtcnn.detect_faces(ivan)  # type: list
github ipazc / mtcnn / mtcnn / mtcnn.py View on Github external
def detect_faces(self, img) -> list:
        """
        Detects bounding boxes from the specified image.
        :param img: image to process
        :return: list containing all the bounding boxes detected with their keypoints.
        """
        if img is None or not hasattr(img, "shape"):
            raise InvalidImage("Image not valid.")

        height, width, _ = img.shape
        stage_status = StageStatus(width=width, height=height)

        m = 12 / self._min_face_size
        min_layer = np.amin([height, width]) * m

        scales = self.__compute_scale_pyramid(m, min_layer)

        stages = [self.__stage1, self.__stage2, self.__stage3]
        result = [scales, stage_status]

        # We pipe here each of the stages
        for stage in stages:
            result = stage(img, result[0], result[1])
github the-house-of-black-and-white / opencv-dnn-demo / face_detectors / mtcnn.py View on Github external
def detect(self, image, include_score=False):
        try:
            faces = [f['box'] for f in self.detector.detect_faces(image) if f['confidence'] >= self.min_confidence]
        except InvalidImage:
            faces = []
        return faces
github instabotai / instabotai / mtcnn / mtcnn.py View on Github external
def detect_faces(self, img) -> list:
        """
        Detects bounding boxes from the specified image.
        :param img: image to process
        :return: list containing all the bounding boxes detected with their keypoints.
        """
        if img is None or not hasattr(img, "shape"):
            raise InvalidImage("Image not valid.")

        height, width, _ = img.shape
        stage_status = StageStatus(width=width, height=height)

        m = 12 / self.__min_face_size
        min_layer = np.amin([height, width]) * m

        scales = self.__compute_scale_pyramid(m, min_layer)

        stages = [self.__stage1, self.__stage2, self.__stage3]
        result = [scales, stage_status]

        # We pipe here each of the stages
        for stage in stages:
            result = stage(img, result[0], result[1])