import cv2 import argparse from face_detector import Face_Detector ap = argparse.ArgumentParser() ap.add_argument('-f', '--face', default='cascade/haarcascade_frontalface_default.xml', help='path to the face cascade') ap.add_argument('-i', '--image', required=True, help='path to the image') args = vars(ap.parse_args()) image = cv2.imread(args['image']) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray = cv2.equalizeHist(gray) fd = Face_Detector(args['face']) faces = fd.detect(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) print("%d face(s) detected" % (len(faces))) for (x, y, w, h) in faces: cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2) cv2.imshow("Faces", image) cv2.waitKey(0) cv2.destroyAllWindows()
fd = Face_Detector(args['face'], args['eyes']) if not args['video']: camera = cv2.VideoCapture(0) else: camera = cv2.VideoCapture(args['video']) if not camera.isOpened: print("Failed to load the frames. Exiting ....") while True: ret, frame = camera.read() if frame is None and not ret: break frame = imutils.resize(frame, width=500) #image = cv2.resize(frame, (480,480)) result = fd.detect(frame) cv2.imshow("faces", result) if cv2.waitKey(1) & 0xFF == ord('q'): break print("exiting....") camera.release() cv2.destroyAllWindows()