added prerecorded video support

This commit is contained in:
Nickiel12 2023-09-30 08:16:33 -07:00
parent f345468cbf
commit 880e039d5e

View file

@ -6,6 +6,12 @@ import time
import os import os
import datetime import datetime
def dir_path(string):
if os.path.exists(string):
return string
else:
raise NotADirectoryError(string)
def init_argparse() -> argparse.ArgumentParser: def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog="FaceDetection", prog="FaceDetection",
@ -22,7 +28,7 @@ def init_argparse() -> argparse.ArgumentParser:
"-o", "--output", action='store_true', help="show the resultant directions" "-o", "--output", action='store_true', help="show the resultant directions"
) )
parser.add_argument( 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( parser.add_argument(
"-s", "--no-screen", action='store_true', help="Do not show the successful frames" "-s", "--no-screen", action='store_true', help="Do not show the successful frames"
@ -72,6 +78,9 @@ def draw_dashboard(keep_stat_line = False):
parser = init_argparse() parser = init_argparse()
args = parser.parse_args() args = parser.parse_args()
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. 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 = cv2.CascadeClassifier(r"./cascades/lbpcascade_frontalface.xml") # CHECK THIS FIRST TROUBLE SHOOTING
faceCascade_default = cv2.CascadeClassifier(r"./cascades/haarcascade_frontalface_default.xml") faceCascade_default = cv2.CascadeClassifier(r"./cascades/haarcascade_frontalface_default.xml")