mirror of
https://github.com/serengil/deepface.git
synced 2025-06-08 20:45:22 +00:00
division by zero problem
This commit is contained in:
parent
68a792b290
commit
b72b2ef05b
@ -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))
|
#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
|
#apply cosine rule
|
||||||
|
|
||||||
cos_a = (b*b + c*c - a*a)/(2*b*c)
|
if b != 0 and c != 0: #this multiplication causes division by zero in cos_a calculation
|
||||||
angle = np.arccos(cos_a) #angle in radian
|
|
||||||
angle = (angle * 180) / math.pi #radian to degree
|
|
||||||
|
|
||||||
#-----------------------
|
cos_a = (b*b + c*c - a*a)/(2*b*c)
|
||||||
#rotate base image
|
angle = np.arccos(cos_a) #angle in radian
|
||||||
|
angle = (angle * 180) / math.pi #radian to degree
|
||||||
|
|
||||||
if direction == -1:
|
#-----------------------
|
||||||
angle = 90 - angle
|
#rotate base image
|
||||||
|
|
||||||
img = Image.fromarray(img_raw)
|
if direction == -1:
|
||||||
img = np.array(img.rotate(direction * angle))
|
angle = 90 - angle
|
||||||
|
|
||||||
#you recover the base image and face detection disappeared. apply again.
|
img = Image.fromarray(img_raw)
|
||||||
faces = face_detector.detectMultiScale(img, 1.3, 5)
|
img = np.array(img.rotate(direction * angle))
|
||||||
if len(faces) > 0:
|
|
||||||
x,y,w,h = faces[0]
|
#you recover the base image and face detection disappeared. apply again.
|
||||||
detected_face = img[int(y):int(y+h), int(x):int(x+w)]
|
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)]
|
||||||
|
|
||||||
#-----------------------
|
#-----------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user