33
44import cv2 .cv2 as cv2
55from cv2 .cv2 import CascadeClassifier
6+ from cv2 .data import haarcascades
67from loguru import logger
78
89from home_guardian .common .debounce_throttle import throttle
910from home_guardian .configuration .application_configuration import application_conf
1011from home_guardian .configuration .thread_pool_configuration import executor
11- from home_guardian .function_collection import get_data_dir , get_resources_dir
12+ from home_guardian .function_collection import get_data_dir
1213from home_guardian .message .email import send_email
1314from home_guardian .opencv .threading import VideoCaptureThreading
1415from home_guardian .repository .detected_face_repository import save
2223
2324_headless : bool = application_conf .get_bool ("headless" )
2425
26+ _haarcascade_frontalface_default = os .path .join (
27+ haarcascades , "haarcascade_frontalface_default.xml"
28+ )
29+ logger .warning (f"_haarcascade_frontalface_default: { _haarcascade_frontalface_default } " )
30+
2531
2632def detect_and_take_photo () -> None :
2733 """
2834 Detect and take photo.
2935 :return: when exception is raised, return None.
3036 """
31- face = CascadeClassifier (f" { get_resources_dir () } /haarcascade_frontalface_alt2.xml" )
37+ face = CascadeClassifier (_haarcascade_frontalface_default )
3238 try :
3339 vid_cap : VideoCaptureThreading = VideoCaptureThreading (0 ).start ()
3440 except Exception as e :
@@ -55,9 +61,7 @@ def process_frame(cascade_classifier: CascadeClassifier, frame) -> None:
5561@logger .catch
5662def async_process_frame (cascade_classifier : CascadeClassifier , frame ) -> None :
5763 gray_frame = cv2 .cvtColor (frame , cv2 .COLOR_BGR2GRAY )
58- faces = cascade_classifier .detectMultiScale (
59- gray_frame , scaleFactor = 1.5 , minNeighbors = 5
60- )
64+ faces = cascade_classifier .detectMultiScale (gray_frame )
6165 for (x , y , w , h ) in faces :
6266 logger .info (
6367 "Detected face, axis(x,y) = ({},{}), width = {} px, h = {} px" , x , y , w , h
0 commit comments