From 880e039d5e4adef62cd622a5f98ad25db953e217 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sat, 30 Sep 2023 08:16:33 -0700 Subject: [PATCH] added prerecorded video support --- Face_Detect with borders.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Face_Detect with borders.py b/Face_Detect with borders.py index 24dc7df..7cc2148 100644 --- a/Face_Detect with borders.py +++ b/Face_Detect with borders.py @@ -6,6 +6,12 @@ import time import os import datetime +def dir_path(string): + if os.path.exists(string): + return string + else: + raise NotADirectoryError(string) + def init_argparse() -> argparse.ArgumentParser: parser = argparse.ArgumentParser( prog="FaceDetection", @@ -22,7 +28,7 @@ def init_argparse() -> argparse.ArgumentParser: "-o", "--output", action='store_true', help="show the resultant directions" ) parser.add_argument( - "-f", "--file", nargs="?", help="File to scan instead of using the camera. Useful for generating training data" + "-f", "--file", type=dir_path, nargs="?", help="File to scan instead of using the camera. Useful for generating training data" ) parser.add_argument( "-s", "--no-screen", action='store_true', help="Do not show the successful frames" @@ -72,7 +78,10 @@ def draw_dashboard(keep_stat_line = False): parser = init_argparse() args = parser.parse_args() -cap = cv2.VideoCapture(0, cv2.IMREAD_GRAYSCALE) # instead of grayscale you can also use -1, 0, or 1. +if args.file: + cap = cv2.VideoCapture(args.file) +else: + cap = cv2.VideoCapture(0, cv2.IMREAD_GRAYSCALE) # instead of grayscale you can also use -1, 0, or 1. faceCascade = cv2.CascadeClassifier(r"./cascades/lbpcascade_frontalface.xml") # CHECK THIS FIRST TROUBLE SHOOTING faceCascade_default = cv2.CascadeClassifier(r"./cascades/haarcascade_frontalface_default.xml") faceCascade_alt = cv2.CascadeClassifier(r"./cascades/haarcascade_frontalface_alt.xml")