def __init__(self, profile_activated): self.profile_activated = profile_activated self.model_path = BASE_DIR + SPERATOR + "facedatabase" + SPERATOR self.svm_model_name = "trained_classifier.pkl" self.image_rep_name = "faces.npy" self.people_rep_name = "people.npy" self.image_folder_path = "images" + SPERATOR if self.profile_activated is True: print("FaceRecognition: initialize face recognizer") self.svm = None self.training = False self.training_id = 0 self.training_name = "Unknown" self.trainingInProgress = False self.identify_threshold = 0.8 self.face_classfier = None if not os.path.exists(self.model_path): os.makedirs(self.model_path) if self.profile_activated is True: print("FaceRecognition: loading prepresentations of kownen persons") try: self.images = np.load(self.model_path + SPERATOR + self.image_rep_name,allow_pickle=True).item() except IOError: if self.profile_activated is True: print("Warning: no image representation file found") self.images = {} try: self.people = np.load(self.model_path + SPERATOR + self.people_rep_name,allow_pickle=True).item() except IOError: if self.profile_activated is True: print("Warning: no people representation file found") self.people = {} self.people["0"] = "Unknown" if self.profile_activated is True: print ("FaceRecognition: try to load saved svm for estimation") try: self.face_classfier = FaceClassifier(self.model_path + SPERATOR + self.svm_model_name) except IOError: if self.profile_activated is True: print ("Warning: no svm saved") self.face_classfier = None if self.profile_activated is True: print ("FaceRecognition: initialisation done") self.tracker_sort = Sort(25,3)
def trainSVM(self): self.trainingInProgress = True if self.profile_activated is True: print ("FaceRecognition: Training SVM on {} labeled images.".format(len(self.images))) d = self.getData() if d is None: self.face_classfier = None if self.profile_activated is True: print ("FaceRecognition: at least 2 persons needed ..") self.trainingInProgress = False return else: (X, y) = d numIdentities = len(set(y + [-1])) if numIdentities <= 1: self.trainingInProgress = False return self.face_classfier = FaceClassifier() self.face_classfier.train(X, y, model='svm', save_model_path=(self.model_path + SPERATOR + self.svm_model_name)) self.saveImageDataAndTrainedNet() print ("training done!") self.trainingInProgress = False
import cv2 import time import numpy as np from detection.FaceDetector import FaceDetector from recognition.FaceRecognition import FaceRecognition from classifier.FaceClassifier import FaceClassifier face_detector = FaceDetector() face_recognition = FaceRecognition() face_classfier = FaceClassifier('./classifier/trained_classifier.pkl') video_capture = cv2.VideoCapture(0) print('Start Recognition!') prevTime = 0 while True: ret, frame = video_capture.read() frame = cv2.resize(frame, (0, 0), fx=1, fy=1) # resize frame (optional) #time.sleep(1) curTime = time.time() # calc fps find_results = [] frame = frame[:, :, 0:3] boxes, scores = face_detector.detect(frame) face_boxes = boxes[np.argwhere(scores>0.3).reshape(-1)] face_scores = scores[np.argwhere(scores>0.3).reshape(-1)] print('Detected_FaceNum: %d' % len(face_boxes)) if len(face_boxes) > 0: for i in range(len(face_boxes)): box = face_boxes[i] cropped_face = frame[box[0]:box[2], box[1]:box[3], :]
return names[ind] def _update_attendance(attendance_list): ''' Updates attendance Args: attend ''' with open(args.attendance_file,"w") as f: attendance_list=[a+"\n" for a in attendance_list] f.writelines(attendance_list) face_detector = FaceDetector(PATH_TO_CKPT=detect_ckpt) face_recognition = FaceRecognition(PATH_TO_CKPT=recog_ckpt) face_classfier = FaceClassifier(args.trained_classifier) face_classfier_svm=FaceClassifier('./classifier/trained_svm.pkl') face_classfier_knn7=FaceClassifier('./classifier/knn_7.pkl') face_classfier_knn7=FaceClassifier('./classifier/knn_5.pkl') face_classfier_rf=FaceClassifier('./classifier/random_forests.pkl') #video_capture = cv2.VideoCapture(args.camera) video_capture = cv2.VideoCapture(0) print('Start Recognition!') prevTime = 0 count=0 attendance_list=[] skip=0 while True: ret, frame = video_capture.read()
class FaceRecognition(object): def __init__(self, profile_activated): self.profile_activated = profile_activated self.model_path = BASE_DIR + SPERATOR + "facedatabase" + SPERATOR self.svm_model_name = "trained_classifier.pkl" self.image_rep_name = "faces.npy" self.people_rep_name = "people.npy" self.image_folder_path = "images" + SPERATOR if self.profile_activated is True: print("FaceRecognition: initialize face recognizer") self.svm = None self.training = False self.training_id = 0 self.training_name = "Unknown" self.trainingInProgress = False self.identify_threshold = 0.8 self.face_classfier = None if not os.path.exists(self.model_path): os.makedirs(self.model_path) if self.profile_activated is True: print("FaceRecognition: loading prepresentations of kownen persons") try: self.images = np.load(self.model_path + SPERATOR + self.image_rep_name,allow_pickle=True).item() except IOError: if self.profile_activated is True: print("Warning: no image representation file found") self.images = {} try: self.people = np.load(self.model_path + SPERATOR + self.people_rep_name,allow_pickle=True).item() except IOError: if self.profile_activated is True: print("Warning: no people representation file found") self.people = {} self.people["0"] = "Unknown" if self.profile_activated is True: print ("FaceRecognition: try to load saved svm for estimation") try: self.face_classfier = FaceClassifier(self.model_path + SPERATOR + self.svm_model_name) except IOError: if self.profile_activated is True: print ("Warning: no svm saved") self.face_classfier = None if self.profile_activated is True: print ("FaceRecognition: initialisation done") self.tracker_sort = Sort(25,3) def __del__(self): if self.profile_activated is True: print ("FaceRecognition: starting destruktor") """ Trains the neural net with all saved images. Therefore every pic is loaded, cropped and representations are created. This uses all neuronal nets, so there need to be available (self.loadingfromimages = True) """ def learnFromPics(self): if self.profile_activated is True: print ("FaceRecognition: loading representations from saved pics") print ("Folder: " + self.model_path + SPERATOR +self.image_folder_path) self.trainingInProgress = True self.people["0"] = "Unknown" time.sleep(5) """ Loop trough every subfolder and get every picture The folder names provide id and the person name """ for folder in glob.glob(self.model_path + SPERATOR + self.image_folder_path + "*"): args = folder.replace(self.model_path + SPERATOR + self.image_folder_path, "") args = args.split(SPERATOR) args = args[0].split("_") for file in glob.glob(folder + SPERATOR +"*"): alignedFace = [] image = cv2.imread(file) image = np.asarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) if image.shape == (160,160,3): if self.profile_activated is True: print(file + " [" + str(image.shape) + "]: image of a face") alignedFace.append(image) else: bbs, scores = face_detector.detect(image) bbs = bbs[np.argwhere(scores > FACE_DETEC_THRESHOLD).reshape(-1)] scores = scores[np.argwhere(scores > FACE_DETEC_THRESHOLD).reshape(-1)] if self.profile_activated is True: print(file + ": found " + str(len(bbs)) + " faces") if len(bbs) < 1: continue for bb in bbs: cropped_face = image[bb[0]:bb[2], bb[1]:bb[3], :] alignedFace.append(cv2.resize(cropped_face, (160, 160), interpolation=cv2.INTER_AREA)) for face in alignedFace: phash = str(imagehash.phash(Image.fromarray(face))) rep = face_recognition.recognize(face) self.images[phash] = Face(rep, int(args[0])) self.people[args[0]] = args[1] if self.profile_activated is True: print ("FaceRecognition: finished loading data from saved images") self.trainSVM() self.trainingInProgress = False """ Saves self.image and self.people """ def saveImageDataAndTrainedNet (self): if self.profile_activated is True: print ("FaceRecognition: saving image representations and people dict") if not os.path.exists(self.model_path): os.makedirs(self.model_path) np.save(self.model_path + SPERATOR + self.image_rep_name, self.images) np.save(self.model_path + SPERATOR + self.people_rep_name, self.people) """ Get the information from self.images and convert it to two list with reps and labels. """ def getData(self): X = [] y = [] for img in self.images.values(): X.append(img.rep) y.append(img.identity) numIdentities = len(set(y + [-1])) - 1 if numIdentities == 0: return None X = np.vstack(X) y = np.array(y) return (X, y) """ Called to train the neural net with all representations currently loaded in self.image. Saves also everything afterwards. """ def trainSVM(self): self.trainingInProgress = True if self.profile_activated is True: print ("FaceRecognition: Training SVM on {} labeled images.".format(len(self.images))) d = self.getData() if d is None: self.face_classfier = None if self.profile_activated is True: print ("FaceRecognition: at least 2 persons needed ..") self.trainingInProgress = False return else: (X, y) = d numIdentities = len(set(y + [-1])) if numIdentities <= 1: self.trainingInProgress = False return self.face_classfier = FaceClassifier() self.face_classfier.train(X, y, model='svm', save_model_path=(self.model_path + SPERATOR + self.svm_model_name)) self.saveImageDataAndTrainedNet() print ("training done!") self.trainingInProgress = False """ Called to process every frame (basically the main function) Need a Frame to process, returns die found identities, confidences and a frame with marks """ def processframe(self, frame): #For profiling this script if self.profile_activated is True: start_time = time.time() if self.trainingInProgress is True: return [],[], frame , caption_frame identities = [] identities_bb = [] confidences = [] caption_frame = np.zeros(frame.shape, np.uint8) """ Searching for everything that look similar to a face Remove scores that are too low """ bbs, scores = face_detector.detect(frame) bbs = bbs[np.argwhere(scores > 0.25).reshape(-1)] scores = scores[np.argwhere(scores > 0.25).reshape(-1)] if self.training is True: if len(bbs) is not 1: if self.profile_activated is True: print ("FaceRecognition: Need to find exacly one Person") return [],[], frame, caption_frame else: if self.profile_activated is True: print ("FaceRecognition: I want to train.. Taking Picture! Please move to differnt angles") pass # For profiling this script if self.profile_activated is True: boundingboxes_time = time.time() loopstart_time = [] alignedFace_time = [] finished_time = [] found_identity_time = [] """ Deside the identity of every boxes found in the frame """ for index,bb in enumerate(bbs): # For profiling this script if self.profile_activated is True: loopstart_time.append(time.time()) confidence = "" identity = "0" """ cropp every face to a 160x160 dimention to pass it into a neuronal net """ cropped_face = frame[bb[0]:bb[2], bb[1]:bb[3], :] alignedFace = cv2.resize(cropped_face, (160, 160), interpolation=cv2.INTER_AREA) # For profiling this script if self.profile_activated is True: alignedFace_time.append(time.time()) if alignedFace is None: # For profiling this script if self.profile_activated is True: finished_time.append(time.time()) continue """ We know the identity if the picture was taken before or is equal to a used image. Otherwise get a feature representation of that face and compare via a neuronal net. """ phash = str(imagehash.phash(Image.fromarray(alignedFace))) if phash in self.images: identity = str(self.images[phash].identity) confidence = "1.0000" # For profiling this script if self.profile_activated is True: found_identity_time.append(time.time()) else: """if we are training a the face_recognition nn can be occupied!""" if self.trainingInProgress is True: return [],[], frame , caption_frame, rep = face_recognition.recognize(alignedFace) if self.training is True: """ If training is enabled, add the representation to self.images and save the new image into a subfolder of the image folder for later training runs. The new image is shown in the top left. """ self.images[phash] = Face(rep, self.training_id) self.people[str(self.training_id)] = self.training_name person_path = self.model_path + SPERATOR + self.image_folder_path + SPERATOR + str(self.training_id) + "_" + str(self.training_name) + SPERATOR if not os.path.exists(person_path): os.makedirs(person_path) cv2.imwrite( person_path + str(phash) +".png",alignedFace) frame[0:160, 0:160, 0] = alignedFace[:, :, 2] frame[0:160, 0:160, 1] = alignedFace[:, :, 1] frame[0:160, 0:160, 2] = alignedFace[:, :, 0] cv2.rectangle(frame, (161, 161), (0, 0), color=(255, 50, 50), thickness=4) # For profiling this script if self.profile_activated is True: found_identity_time.append(time.time()) elif self.face_classfier is not None: """ If a classifier is existent, get a prediction who this face might be. Compare the confidence to a threshold to evade to low scores. """ rep = rep.reshape(1, -1) predictions = self.face_classfier.classify(rep).ravel() maxI = np.argmax(predictions) confidence = str(predictions[maxI].round(5)) if predictions[maxI] <= self.identify_threshold: maxI = 0 identity = str(maxI) # For profiling this script if self.profile_activated is True: found_identity_time.append(time.time()) else: # For profiling this script if self.profile_activated is True: found_identity_time.append(time.time()) """ Append the identity in any case with the highest confidence.""" identities.append(identity) identities_bb.append((bb[1], bb[0], bb[3], bb[2])) confidences.append(confidence) """ Mark everyone in the frame """ cv2.rectangle(frame, (bb[1], bb[0]), (bb[3], bb[2]), color=(255,50,50), thickness=2) cv2.rectangle(caption_frame, (bb[1], bb[0]), (bb[3], bb[2]), color=(255,50,50), thickness=2) cv2.putText(frame, self.people[identity] , (bb[1], bb[0] - 10), cv2.FONT_HERSHEY_DUPLEX, fontScale=1, color=(255, 50, 50), thickness=2) cv2.putText(frame, confidence, (bb[1], bb[2] + 30), cv2.FONT_HERSHEY_DUPLEX, fontScale=1, color=(255, 50, 50), thickness=2) cv2.putText(caption_frame, self.people[identity] , (bb[1], bb[0] - 10), cv2.FONT_HERSHEY_DUPLEX, fontScale=1, color=(255, 50, 50), thickness=2) cv2.putText(caption_frame, confidence, (bb[1], bb[2] + 30), cv2.FONT_HERSHEY_DUPLEX, fontScale=1, color=(255, 50, 50), thickness=2) # For profiling this script if self.profile_activated is True: finished_time.append(time.time()) # For profiling this script if self.profile_activated is True: end_time = time.time() profile_string = "TIMES: bounding boxes: " + str( format(boundingboxes_time - start_time,PROFILE_ROUND )) profile_string += ", face(aligne, recognize, annotate) {" for i in range(0, len(loopstart_time)): profile_string += " (" + str(format(alignedFace_time[i] - loopstart_time[i],PROFILE_ROUND)) profile_string += "," + str(format(found_identity_time[i] - alignedFace_time[i],PROFILE_ROUND)) profile_string += "," + str(format(finished_time[i] - found_identity_time[i],PROFILE_ROUND)) + ")" profile_string += " }" profile_string += ", entire: " + str(format(end_time - start_time,PROFILE_ROUND)) profile_string += ", fps: " + str(format(1.0 / (end_time - start_time),PROFILE_ROUND)) print (profile_string) return identities,identities_bb,confidences,frame, caption_frame def findFacesTracked(self, frame): tracking_dets = [] bbs, scores = face_detector.detect(frame) bbs = bbs[np.argwhere(scores > 0.25).reshape(-1)] scores = scores[np.argwhere(scores > 0.25).reshape(-1)] for i in range (0, len(bbs)): tracking_dets.append([int(bbs[i][1]),int(bbs[i][0]),int(bbs[i][3]),int(bbs[i][2]),int(100 * scores[i])]) #if len(tracking_dets) == 0: # tracking_dets.append([]) trackers = self.tracker_sort.update(np.asarray(tracking_dets)) int_trackers = [] for tracker in trackers: if tracker[0] < 0: tracker[0] = 0 if tracker[1] < 0: tracker[1] = 0 if tracker[2] > 1079: tracker[2] = 1079 if tracker[3] > 1919: tracker[3] = 1919 int_trackers.append([int(tracker[0]),int(tracker[1]),int(tracker[2]),int(tracker[3]),int(tracker[4])]) return int_trackers def identifyFacesInBB(self, frame, bb): cropped_face = cv2.UMat(frame[bb[1]:bb[3], bb[0]:bb[2], :]) alignedFace = cv2.UMat.get(cv2.resize(cropped_face, (160, 160), interpolation=cv2.INTER_AREA)) rep = face_recognition.recognize(alignedFace) rep = rep.reshape(1, -1) predictions = self.face_classfier.classify(rep).ravel() maxI = np.argmax(predictions) if predictions[maxI] <= self.identify_threshold: maxI = 0 return (self.people[str(maxI)] , maxI, predictions[maxI])
import cv2 import time import numpy as np from detection.FaceDetector import FaceDetector from recognition.FaceRecognition import FaceRecognition from classifier.FaceClassifier import FaceClassifier VIDEO_INPUT_FILE = './media/test_video/Zidane_1.avi' VIDEO_OUTPUT_FILE = './media/test_video_output/Zidane_Recognition_1.avi' FACE_CLASSIFIER_MODEL = './classifier/trained_classifier_lfw.pkl' face_detector = FaceDetector() face_recognition = FaceRecognition() face_classfier = FaceClassifier(FACE_CLASSIFIER_MODEL) video_capture = cv2.VideoCapture(VIDEO_INPUT_FILE) fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter(VIDEO_OUTPUT_FILE, fourcc, 24.0, (int(video_capture.get(3)), int(video_capture.get(4)))) print('Start Recognition!') prevTime = 0 while video_capture.isOpened(): ret, frame = video_capture.read() curTime = time.time() # calc fps find_results = [] frame = frame[:, :, 0:3] boxes, scores = face_detector.detect(frame) face_boxes = boxes[np.argwhere(scores > 0.3).reshape(-1)]
"all" ] input_folder = path.join(path.abspath(path.curdir), "data", "input") people_folders = None number_imgs_list = [] embeddings = [] embeddings_ids = [] embeddings_df = None people_df = None vector_size = None face_classifier = FaceClassifier() def download(file_path, url): import requests import math r = requests.get(url, stream=True) total_size = int(r.headers.get('content-length')) block_size = 1024 with open(file_path, 'wb') as f: for data in tqdm(r.iter_content(block_size), total=math.ceil(total_size // block_size), desc="Download", unit='B', unit_scale=True, unit_divisor=1024): f.write(data)
def main(args): face_detector = FaceDetector() face_recognition = FaceRecognition(args.model) face_classfier = FaceClassifier(args.classifier_filename) video_capture = cv2.VideoCapture(args.video_input) output_file = './media/result/' + os.path.basename( args.video_input) + '_result.avi' fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter( output_file, fourcc, 24.0, (int(video_capture.get(3)), int(video_capture.get(4)))) print('Start Recognition!') prevTime = 0 while video_capture.isOpened(): ret, frame = video_capture.read() curTime = time.time() # calc fps find_results = [] frame = frame[:, :, 0:3] boxes, scores = face_detector.detect(frame) face_boxes = boxes[np.argwhere(scores > 0.3).reshape(-1)] face_scores = scores[np.argwhere(scores > 0.3).reshape(-1)] print('Detected_FaceNum: %d' % len(face_boxes)) if len(face_boxes) > 0: for i in range(len(face_boxes)): box = face_boxes[i] cropped_face = frame[box[0]:box[2], box[1]:box[3], :] cropped_face = cv2.resize(cropped_face, (160, 160), interpolation=cv2.INTER_AREA) feature = face_recognition.recognize(cropped_face) name = face_classfier.classify(feature) cv2.rectangle(frame, (box[1], box[0]), (box[3], box[2]), (0, 255, 0), 2) # plot result idx under box text_x = box[1] text_y = box[2] + 20 cv2.putText(frame, name, (text_x, text_y), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), thickness=1, lineType=2) else: print('Unable to align') sec = curTime - prevTime prevTime = curTime fps = 1 / (sec) str = 'FPS: %2.3f' % fps text_fps_x = len(frame[0]) - 150 text_fps_y = 20 cv2.putText(frame, str, (text_fps_x, text_fps_y), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 0), thickness=1, lineType=2) out.write(frame) video_capture.release() out.release() cv2.destroyAllWindows()
# modify the default parameters of np.load np.load.__defaults__=(None, True, True, 'ASCII') import align.detect_face as detect_face import cv2 import numpy as np import tensorflow as tf from lib.face_utils import judge_side_face from lib.utils import Logger, mkdir from project_root_dir import project_dir from src.sort import Sort from recognition.FaceRecognition import FaceRecognition from classifier.FaceClassifier import FaceClassifier face_classfier = FaceClassifier('./classifier/trained_classifier.pkl') face_recognition = FaceRecognition() logger = Logger() def main(): global colours, img_size args = parse_args() # videos_dir = args.videos_dir output_path = args.output_path no_display = args.no_display detect_interval = args.detect_interval # you need to keep a balance between performance and fluency margin = args.margin # if the face is big in your video ,you can set it bigger for tracking easiler scale_rate = args.scale_rate # if set it smaller will make input frames smaller show_rate = args.show_rate # if set it smaller will dispaly smaller frames face_score_threshold = args.face_score_threshold
def _update_attendance(attendance_list): ''' Updates attendance Args: attend ''' with open(args.attendance_file, "w") as f: attendance_list = [a + "\n" for a in attendance_list] f.writelines(attendance_list) face_detector = FaceDetector(PATH_TO_CKPT=detect_ckpt) face_recognition = FaceRecognition(PATH_TO_CKPT=recog_ckpt) face_classfier = FaceClassifier(args.trained_classifier) #video_capture = cv2.VideoCapture(args.camera) print('Start Recognition!') prevTime = 0 count = 0 attendance_list = [] i = 1 while True: j = 37 + i path = './media/train_classifier/milind/' frame = cv2.imread(path + 'WhatsApp Image 2018-11-01 at 9.23.%d PM.jpeg' % j) print('%dth recognition' % i) i += 1
import numpy as np from classifier.FaceClassifier import FaceClassifier #Training classifiers after obtaining the feaure vectors from the recognition model features = np.load('./npy files/features.npy') labels = np.load('./npy files/labels.npy') face_classifier = FaceClassifier('./classifier/trained_svm.pkl') Svm = face_classifier.train( features, labels, model='SVM', save_model_path='./classifier/new_classifiers/trained_svm.pkl') #KNN = face_classifier.train(features,labels,model='knn',save_model_path='./classifier/trained_classifier.pkl') KNN_5 = face_classifier.train( features, labels, model='knn', knn_neighbours=5, save_model_path='./classifier/new_classifiers/knn_5.pkl') KNN_7 = face_classifier.train( features, labels, model='knn', knn_neighbours=7, save_model_path='./classifier/new_classifiers/knn_7.pkl') random_forests = face_classifier.train( features, labels, model='random-forests', save_model_path='./classifier/new_classifiers/random_forests.pkl') Svm_poly = face_classifier.train( features,
import cv2 import os import numpy as np from recognition.facenet import get_dataset from recognition.FaceRecognition import FaceRecognition from detection.FaceDetector import FaceDetector from classifier.FaceClassifier import FaceClassifier datadir = './media/train_classifier' face_detector = FaceDetector() face_recognition = FaceRecognition() face_classfier = FaceClassifier() def get_image_paths_and_labels(dataset): image_paths_flat = [] labels_flat = [] for i in range(len(dataset)): image_paths_flat += dataset[i].image_paths labels_flat += [dataset[i].name] * len(dataset[i].image_paths) return image_paths_flat, labels_flat dataset = get_dataset(datadir) paths, labels = get_image_paths_and_labels(dataset) print('Number of classes: %d' % len(dataset)) print('Number of images: %d' % len(paths)) # Run forward pass to calculate embeddings
if args.classifier == "SVM": model_type = "SVM" elif args.classifier == "random-forests": model_type = "random-forests" elif args.classifier == "KNN": model_type = "knn" elif args.classifier == "DNN": model_type = "dnn" mobilenet = False if args.recognition_model == "mobilenet_v2": mobilenet = True face_detector = FaceDetector(PATH_TO_CKPT=detect_ckpt) face_recognition = FaceRecognition(PATH_TO_CKPT=recog_ckpt) face_classfier = FaceClassifier(args.trained_classifier) def get_image_paths_and_labels(dataset): image_paths_flat = [] labels_flat = [] for i in range(len(dataset)): image_paths_flat += dataset[i].image_paths labels_flat += [dataset[i].name] * len(dataset[i].image_paths) return image_paths_flat, labels_flat dataset = get_dataset(datadir) paths, labels = get_image_paths_and_labels(dataset) print('Number of classes: %d' % len(dataset)) print('Number of images: %d' % len(paths))
import time import cv2 import numpy as np from classifier.FaceClassifier import FaceClassifier from detection.FaceDetector import FaceDetector from embeddings.FaceEmbeddings import FaceEmbeddings model = input("Choose a model> ") # model = "knn" face_detector = FaceDetector() face_recognition = FaceEmbeddings() face_classifier = FaceClassifier( f'./classifier/{model.lower()}_classifier.pkl') video_capture = cv2.VideoCapture(0) prevTime = 0 cv2.namedWindow("Video", cv2.WINDOW_NORMAL) print('Start Recognition!') while True: ret, frame = video_capture.read() # if not ret: # break frame = cv2.resize(frame, (0, 0), fx=1, fy=1) # resize frame (optional) curTime = time.time() # calc fps