def training(dataDir_Name): """Gather the available faces data to return faces, and labels . Each person's faces folder name should be follow the following convention.""" """ dataDir_Name ---> ---> s1 ---> s2 and so on... """ faces = [] # for storing faces labels = [] # for storing labels dirs = os.listdir(dataDir_Name) for dir in dirs: if not dir.startswith( 's' ): # check for faces folder name is not matched the convention then skip. continue label = int(dir.replace('s', '')) # getting label names subject_dir = dataDir_Name + '/' + dir # getting subjects directory subject_images = os.listdir(subject_dir) # getting subjects images for image in subject_images: # iterating through all the available images. if image.startswith('.'): continue img_path = subject_dir + '/' + image print(img_path) person = cv2.imread(img_path) face, rect = detectFace(person) if face is not None: faces.append(face) labels.append(label) return faces, labels
def predict(image, face_recognizer): """Predicts face on the image and returns the image.""" try: img = image.copy( ) # getting the copy of image so that original image doesn't get affected. except AttributeError: print("Test image is empty.") exit() face, rect = detectFace(img) label, confidence = face_recognizer.predict(face) labelText = subjects[label] drawRect(img, rect) drawText(img, labelText, rect[0], rect[1] - 5) return img
if(bodyPosition=="front-left-weight"): jd.moveJoint(jd.RIGHT_FRONT_ARM, arm_zero_pos-50) jd.moveJoint(jd.LEFT_FRONT_ARM, arm_zero_pos-70) jd.moveJoint(jd.RIGHT_BACK_ARM, arm_zero_pos) jd.moveJoint(jd.LEFT_BACK_ARM, arm_zero_pos) offset_neck = -10 #muove la testa alla ricerca di un volto for degreeH in [-15, -20, -25, -30, -35]: for degreeW in [-15, 0, 15, -20, 20]: #aggiorna la posizione della testa (telecamera) jd.moveJoint(jd.HEAD, degreeH) jd.moveJoint(jd.NECK, degreeW) #cerca una faccia detected = dt.detectFace(debug=DEBUG) #se trova la faccia la segue if detected is not None: print("found face %s" % (str(detected))) neckDegree = 0 headDegree = 0 faceRect = detected[-1:] for _ in range(1000): faceRect, neckDegree, headDegree = dt.followFace(neckDegree, headDegree) if(faceRect is None): print("loss face") break
if(bodyPosition=="front-left-weight"): jd.moveJoint(jd.RIGHT_FRONT_ARM, arm_zero_pos-50) jd.moveJoint(jd.LEFT_FRONT_ARM, arm_zero_pos-70) jd.moveJoint(jd.RIGHT_BACK_ARM, arm_zero_pos) jd.moveJoint(jd.LEFT_BACK_ARM, arm_zero_pos) offset_neck = -10 #muove la testa alla ricerca di un volto for degreeH in [-15, -20, -25, -30, -35]: for degreeW in [-15, 0, 15, -20, 20]: #aggiorna la posizione della testa (telecamera) jd.moveJoint(jd.HEAD, degreeH) jd.moveJoint(jd.NECK, degreeW) #cerca una faccia detected = dt.detectFace(debug=True) #se trova la faccia la segue if detected is not None: print("found face %s" % (str(detected))) neckDegree = 0 headDegree = 0 faceRect = detected[-1:] for _ in range(1000): faceRect, neckDegree, headDegree = dt.followFace(neckDegree, headDegree) if(faceRect is None): print("loss face") break
# from . import dataCap, detector, train from detector import detectFace from dataCap import capture from train import train import os print("Hello User!\nThis is Face Recognition application.") while True: print( "\nWhat do You wanna DO?\n 1. Recognize A Face.\n 2. Upload New Face.\n 3. End Program" ) c = input(" Choice: ") if c == "1": detectFace() print("Rec Start!") elif c == "2": input("Press Enter to Click a Photo (5 photos needed)...") capture() a = input("Press Enter to start Training on the new Data...") train() elif c == "3": break else: print("Wrong Input") os.system('cls') print("The End")