Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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