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):
"""
MTCNN detects invalid images
:return:
"""
ivan = cv2.imread("example.py")
with self.assertRaises(InvalidImage):
result = mtcnn.detect_faces(ivan) # type: list
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])
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
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])