def restart_visualisation(): # initialize the bounding box coordinates of the object we are going to track initBB = None # initialize the FPS throughput estimator fps = None # id of img img_id = 0 video_capture = cv2.VideoCapture(camera_port) # + cv2.CAP_DSHOW) # video_capture.set(cv2.CAP_PROP_FRAME_WIDTH,camera_width) # video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT,camera_height) faces,faceID,name_dict=fr.labels_for_training_data('../face_reco_app/dataset') face_recognizer=fr.train_classifier(faces,faceID) param_track = False state = 0 while state == 0: # Capture frame-by-frame ret, test_img = video_capture.read() if test_img is None: video_capture = cv2.VideoCapture(camera_port) # + cv2.CAP_DSHOW) # video_capture.set(cv2.CAP_PROP_FRAME_WIDTH,camera_width) # video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT,camera_height) ret, test_img = video_capture.read() if test_img is not None: faces_detected,gray_img = fr.detect_face(test_img) key = cv2.waitKey(1) & 0xFF # face detect par if param_track == False : for face in faces_detected: (x,y,w,h)=face roi_gray=gray_img[y:y+h,x:x+w] label,confidence=face_recognizer.predict(roi_gray) print("\nconfidence:",confidence) print("label :",label) if confidence < 100: fr.draw_rect(test_img,face) predicted_name=name_dict[label] fr.put_text(test_img,predicted_name,x,y) else: fr.draw_rect(test_img,face) predicted_name="John Doe" fr.put_text(test_img,predicted_name,x,y) ret, jpeg = cv2.imencode('.jpg', test_img) yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + jpeg.tobytes() + b'\r\n')
import numpy as np import cv2 import os import face_recognition as fr #print(fr) test_img = cv2.imread(r'E:\Projects\Test_image.jpg') faces_detected, gray_img = fr.faceDetection(test_img) print("Face Detected: ", faces_detected) #Training faces, faceID = fr.labels_for_training_data(r'E:\Projects\images') face_recognizer = fr.trainClassifier(faces, faceID) face_recognizer.save(r'E:\Projects\trainingData.yml') name = {0: 'Yash', 1: 'Diksha', 2: 'Yana'} for face in faces_detected: (x, y, w, h) = face roi_gray = gray_img[y:y + w, x:x + h] label, confidence = face_recognizer.predict(roi_gray) print(label) print(confidence) fr.draw_rect(test_img, face) predict_name = name[label] fr.put_text(test_img, predict_name, x, y) resized_img = cv2.resize(test_img, (1000, 700))
'C:\\Users\\Yadvi\\PycharmProjects\\face\\training\\0\\289002.1.jpg' ) #test_img path faces_detected, gray_img = fr.faceDetection(test_img) print("faces_detected:", faces_detected) ################################################################testing######################################################################### #for (x,y,w,h) in faces_detected: # cv2.rectangle(test_img,(x,y),(x+w,y+h),(255,0,0),thickness=3) #resized_img = cv2.resize(test_img,(1000,700)) #cv2.imshow("Face Detection",resized_img) #cv2.waitKey(0) #cv2.destroyAllWindows() ################################################################################################################################################ #Comment belows lines when running this program second time.Since it saves training.yml file in directory faces, faceID = fr.labels_for_training_data( 'C:\\Users\\Yadvi\\PycharmProjects\\face\\training') face_recognizer = fr.train_classifier(faces, faceID) #face_recognizer.write('trainingData.yml') name = { 0: "Virat Kohli", 1: "Barack Obama" } #creating dictionary containing names for each label ############################################################ testing ######################################################################### #face_recognizer = cv2.face.LBPHFaceRecognizer_create() #face_recognizer.read('C:\\Users\\Yadvi\\PycharmProjects\\face\\trainingData.yml') #test_img=cv2.imread('C:\\Users\\Yadvi\\Desktop\\bo_test.jpg') ################################################################################################################################################
import numpy as np import cv2 import os import face_recognition as fr print(fr) test_img = cv2.imread(r'D:\Python\Projects\Face Recognition\test_image5.jfif' ) # Give path to the image which you want to test faces_detected, gray_img = fr.faceDetection(test_img) print('Face Detected: ', faces_detected) #Training will begin from here faces, faceID = fr.labels_for_training_data( "D:\Python\Projects\Face Recognition\Image") face_recogniser = fr.train_Classifier(faces, faceID) face_recogniser.save('D:/Python/Projects/Face Recognition/TrainingData.yml' ) # To save the trained model. Just give the path. # Assign labels to images folder name = { 0: "Rhythem Jain", 1: "Mark Zuckerberg", 2: "Hrithik Roshan", 3: "Deepika Padukone", 4: "Emma Watson" } for face in faces_detected: (x, y, w, h) = face roi_gray = gray_img[y:y + h, x:x + h]
""" import numpy as np import cv2 import os import face_recognition as FR print(FR) test_img=cv2.imread('G:\Data Science Project\LBPH Face Recongition\Test_image.jpg') faces_detected,gray_img=FR.faceDetection(test_img) cv2.imshow print("Faces Detected",faces_detected) #Initializing the training faces,face_ID=FR.labels_for_training_data(r'G:\Data Science Project\LBPH Face Recongition\capture\0') face_recognizer=FR.train_classifier(faces,face_ID) face_recognizer.save(r'G:\Data Science Project\LBPH Face Recongition\trainingData.yml') name={0:'Yashraj/nData Scientist'} for face in faces_detected: (x,y,w,h)=face roi_gray=gray_img[y:y+w,x:x+h] label,confidence=face_recognizer.predict(roi_gray) print(label) print(confidence) FR.draw_rect(test_img,face) predict_name=name[label] FR.put_text1(test_img,predict_name,x,y)
import numpy as numpy import cv2 import os import face_recognition as fr test_img=cv2.imread(r"D:\project\face recognition\test_img.jpeg") faces_detected,gray_img=fr.faceDetection(test_img) print("Face Detected: ",faces_detected) faces,faceID=fr.labels_for_training_data(r"D:\project\face recognition\images") face_recognizer=fr.train_Classifier(faces,faceID) face_recognizer.save(r"D:\project\face recognition\trainingData.yml") name={0:'pranay'} for face in faces_detected: (x,y,w,h)=face roi_gray=gray_img[y:y+w,x:x+h] label,confidence=face_recognizer.predict(roi_gray) print(label) print(confidence) fr.draw_rect(test_img,face) predict_name=name[label] fr.put_text(test_img,predict_name,x,y) resized_img=cv2.resize(test_img,(1000,700))
import cv2 import os import face_recognition as fr print(fr) #Give path to the image which you want to test test_img = cv2.imread(r'D:\FaceRecognitionLBPH\Test_img.jpg') faces_detected, gray_img = fr.faceDetection(test_img) print("face Detected: ", faces_detected) #Training begin #Give path to the train-images folder which has both labeled folder as 0 and 1 faces, faceID = fr.labels_for_training_data(r'D:\FaceRecognitionLBPH\Image') face_recognizer = fr.train_classifier(faces, faceID) #It will save the trained model. Just give path to where you want to save face_recognizer.save(r'D:\FaceRecognitionLBPH\trainedData.yml') #Change names accordingly. If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1. name = {0: "Bibek", 1: "2nd img bibek"} for face in faces_detected: (x, y, w, h) = face roi_gray = gray_img[y:y + h, x:x + h] label, confidence = face_recognizer.predict(roi_gray) print("Confidence :", confidence) print("label :", label) fr.draw_rect(test_img, face)
import cv2 import os import face_recognition as fr #print(fr) test_img = cv2.imread( r'C:\Users\Harsha\AppData\Local\Programs\Python\Python38\python project\face recognition\test_img2.jpeg' ) faces_detected, gray_img = fr.faceDetection(test_img) #cv2.imshow(faces_detected) print("face Detected: ", faces_detected) #training will being from here faces, faceID = fr.labels_for_training_data( r'D:\python project datasets\images') face_recognizer = fr.train_Classifier(faces, faceID) face_recognizer.save( r'C:\Users\Harsha\AppData\Local\Programs\Python\Python38\python project\face recognition\trainingData.yml' ) name = {0: 'Harsha'} for face in faces_detected: (x, y, w, h) = face roi_gray = gray_img[y:y + w, x:x + h] label, confidence = face_recognizer.predict(roi_gray) print(label) print(confidence) fr.draw_rect(test_img, face) predict_name = name[label]
import numpy as np import cv2 import os import face_recognition as fr print(fr) test_img = cv2.imread(r'C:\Users\msath\Desktop\LBPH\pykara.jpg') faces_detected, gray_img = fr.faceDetection(test_img) print("Face Detected: ", faces_detected) #Training faces, faceID = fr.labels_for_training_data( r'C:\Users\msath\Desktop\LBPH\images') face_recognizer = fr.train_classifier(faces, faceID) face_recognizer.save(r'C:\Users\msath\Desktop\LBPH\trainingData.yml') name = {0: 'Saan'} for face in faces_detected: (x, y, w, h) = face roi_gray = gray_img[y:y + h, x:x + h] label, confidence = face_recognizer.predict(roi_gray) print("Confidence: ", confidence) print("Label: ", label) fr.draw_rect(test_img, face) predicted_name = name[label] fr.put_text(test_img, predicted_name, x, y)
import numpy as np import cv2 import os import face_recognition as fr test_img=cv2.imread(r'C:\Users\denio\Desktop\Courses & Certificates\courses\DataScience\face recog own\test.jpeg') faces_detected,gray_img=fr.faceDetection(test_img) print("Face Detected: ",faces_detected) faces,face_id=fr.labels_for_training_data(r'C:\Users\denio\Desktop\Courses & Certificates\courses\DataScience\face recog own\images') face_recognizer=fr.train_Classifier(faces,face_id) face_recognizer.save(r'C:\Users\denio\Desktop\Courses & Certificates\courses\DataScience\face recog own\trainingdata.yml') name={0:'Denio'} for face in faces_detected: (x,y,w,h)=face roi_gray=gray_img[y:y+w,x:x+h] label,confidence=face_recognizer.predict(roi_gray) print(label) print(confidence) fr.draw_rectangle(test_img,face) predict_name=name[label] fr.put_text(test_img,predict_name,x,y) resized_img=cv2.resize(test_img,(1000,700))
import os import face_recognition as fr test_img = cv2.imread( r'/Users/nirajpaliwal/Documents/Python For Data Science & ML/Data-Science-Projects/06 - Face Recognition/test_img.jpg' ) faces_detected, gray_img = fr.faceDetection(test_img) # cv2.imshow(gray_img) print('Face Detected : ', faces_detected) # Training will begin from here faces, faceID = fr.labels_for_training_data( r'/Users/nirajpaliwal/Documents/Python For Data Science & ML/Data-Science-Projects/06 - Face Recognition/images' ) face_recognizer = fr.train_classifier(faces, faceID) face_recognizer.save( r'/Users/nirajpaliwal/Documents/Python For Data Science & ML/Data-Science-Projects/06 - Face Recognition/trainingData.yml' ) name = {0: 'Neeraj'} for face in faces_detected: (x, y, w, h) = face roi_gray = gray_img[y:y + w, x:x + h] label, confidence = face_recognizer.predict(roi_gray) print(label) print(confidence) fr.draw_rectangle(test_img, face)