From 08ce14e15149e557f68b7dd8465e4eafdffc8ddb Mon Sep 17 00:00:00 2001 From: serengil Date: Tue, 8 Dec 2020 09:49:36 +0300 Subject: [PATCH] eye detector wasn't initialized for ssd backend --- deepface/commons/functions.py | 20 ++++++++++++++------ tests/unit_tests.py | 8 ++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 4f16cc2..ac7638d 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -40,19 +40,27 @@ def initialize_detector(detector_backend): home = str(Path.home()) + #eye detector is common for opencv and ssd + if detector_backend == 'opencv' or detector_backend == 'ssd': + opencv_path = get_opencv_path() + eye_detector_path = opencv_path+"haarcascade_eye.xml" + + if os.path.isfile(eye_detector_path) != True: + raise ValueError("Confirm that opencv is installed on your environment! Expected path ",eye_detector_path," violated.") + + global eye_detector + eye_detector = cv2.CascadeClassifier(eye_detector_path) + + #------------------------------ + #face detectors if detector_backend == 'opencv': opencv_path = get_opencv_path() - face_detector_path = opencv_path+"haarcascade_frontalface_default.xml" - eye_detector_path = opencv_path+"haarcascade_eye.xml" - + if os.path.isfile(face_detector_path) != True: raise ValueError("Confirm that opencv is installed on your environment! Expected path ",face_detector_path," violated.") face_detector = cv2.CascadeClassifier(face_detector_path) - - global eye_detector - eye_detector = cv2.CascadeClassifier(eye_detector_path) elif detector_backend == 'ssd': diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 0715110..8e2c654 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -17,14 +17,14 @@ print("-----------------------------------------") print("Face detectors test") -print("opencv detector") -res = DeepFace.verify(dataset, detector_backend = 'opencv') -print(res) - print("ssd detector") res = DeepFace.verify(dataset, detector_backend = 'ssd') print(res) +print("opencv detector") +res = DeepFace.verify(dataset, detector_backend = 'opencv') +print(res) + print("dlib detector") res = DeepFace.verify(dataset, detector_backend = 'dlib') print(res)