11import mediapipe as mp
22import cv2
33import numpy as np
4+ import os
45
56class FaceQA ():
67 '''
@@ -31,7 +32,7 @@ def check_face(self):
3132 return self ._return_all_false_result ()
3233
3334 # Haarcascade is default to validade other params
34- model_path = ' models/haarcascade_frontalface_default.xml'
35+ model_path = os . path . dirname ( __file__ ) + '/ models/haarcascade_frontalface_default.xml'
3536 image = cv2 .imread (self .image_path )
3637
3738 gray = cv2 .cvtColor (image , cv2 .COLOR_BGR2GRAY )
@@ -56,7 +57,7 @@ def _face_detection_v1(self) -> (bool, bool):
5657 '''
5758 Using HaarCascade to Face Classification
5859 '''
59- model_path = ' models/haarcascade_frontalface_default.xml'
60+ model_path = os . path . dirname ( __file__ ) + '/ models/haarcascade_frontalface_default.xml'
6061 image = cv2 .imread (self .image_path )
6162
6263 # To gray scale
@@ -84,7 +85,7 @@ def _face_detection_v2(self) -> bool:
8485 '''
8586 Using MediaPipe to Face Classification
8687 '''
87- model_path = ' models/blaze_face_short_range.tflite'
88+ model_path = os . path . dirname ( __file__ ) + '/ models/blaze_face_short_range.tflite'
8889
8990 BaseOptions = mp .tasks .BaseOptions
9091 FaceDetector = mp .tasks .vision .FaceDetector
@@ -158,7 +159,7 @@ def _eye_is_good(self, gray_image, face_image) -> bool:
158159 '''
159160 Using HaarCascade to Eyes Classification
160161 '''
161- model_path = ' models/haarcascade_eye.xml'
162+ model_path = os . path . dirname ( __file__ ) + '/ models/haarcascade_eye.xml'
162163
163164 eye_cascade = cv2 .CascadeClassifier (model_path )
164165
@@ -182,7 +183,7 @@ def _is_smiling(self, face_cascade, face_image) -> bool:
182183 '''
183184 Using HaarCascade to Face Classification
184185 '''
185- model_path = ' models/haarcascade_smile.xml'
186+ model_path = os . path . dirname ( __file__ ) + '/ models/haarcascade_smile.xml'
186187
187188 gray = cv2 .cvtColor (face_image , cv2 .COLOR_BGR2GRAY )
188189
0 commit comments