From b72b2ef05bb6251d1fa3ec9f887950b2e2ff9bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eefik=20Serangil?= Date: Sun, 28 Jun 2020 11:28:14 +0300 Subject: [PATCH] division by zero problem --- deepface/commons/functions.py | 43 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 286af4c..1ec650c 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -197,7 +197,12 @@ def detectFace(img, target_size=(224, 224), grayscale = False, enforce_detection #-------------------------------- - faces = face_detector.detectMultiScale(img, 1.3, 5) + faces = [] + + try: + faces = face_detector.detectMultiScale(img, 1.3, 5) + except: + pass #print("found faces in ",image_path," is ",len(faces)) @@ -265,24 +270,26 @@ def detectFace(img, target_size=(224, 224), grayscale = False, enforce_detection #----------------------- #apply cosine rule - cos_a = (b*b + c*c - a*a)/(2*b*c) - angle = np.arccos(cos_a) #angle in radian - angle = (angle * 180) / math.pi #radian to degree + if b != 0 and c != 0: #this multiplication causes division by zero in cos_a calculation - #----------------------- - #rotate base image - - if direction == -1: - angle = 90 - angle - - img = Image.fromarray(img_raw) - img = np.array(img.rotate(direction * angle)) - - #you recover the base image and face detection disappeared. apply again. - faces = face_detector.detectMultiScale(img, 1.3, 5) - if len(faces) > 0: - x,y,w,h = faces[0] - detected_face = img[int(y):int(y+h), int(x):int(x+w)] + cos_a = (b*b + c*c - a*a)/(2*b*c) + angle = np.arccos(cos_a) #angle in radian + angle = (angle * 180) / math.pi #radian to degree + + #----------------------- + #rotate base image + + if direction == -1: + angle = 90 - angle + + img = Image.fromarray(img_raw) + img = np.array(img.rotate(direction * angle)) + + #you recover the base image and face detection disappeared. apply again. + faces = face_detector.detectMultiScale(img, 1.3, 5) + if len(faces) > 0: + x,y,w,h = faces[0] + detected_face = img[int(y):int(y+h), int(x):int(x+w)] #-----------------------