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

To help you get started, we’ve selected a few fer 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 justinshenk / fer / tests / test_fer.py View on Github external
def test_detect_faces_invalid_content(self):
        """
        FER detects invalid images
        :return:
        """
        justin = cv2.imread("example.py")

        with self.assertRaises(InvalidImage):
            result = detector.detect_emotions(justin)  # type: list
github justinshenk / fer / src / fer / fer.py View on Github external
def detect_emotions(self, img: np.ndarray) -> list:
        """
        Detects bounding boxes from the specified image with ranking of emotions.
        :param img: image to process (BGR or gray)
        :return: list containing all the bounding boxes detected with their emotions.
        """
        if img is None or not hasattr(img, "shape"):
            raise InvalidImage("Image not valid.")

        emotion_labels = self._get_labels()

        face_rectangles = self.find_faces(img, bgr=True)

        gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        emotions = []
        for face_coordinates in face_rectangles:
            face_coordinates = self.tosquare(face_coordinates)
            x1, x2, y1, y2 = self.__apply_offsets(face_coordinates)

            if y1 < 0 or x1 < 0:
                gray_img = self.pad(gray_img)
                x1 += 40
                x2 += 40

fer

Facial expression recognition from images

MIT
Latest version published 1 year ago

Package Health Score

44 / 100
Full package analysis