Пример #1
0
def face():
    speak('Processing Facial Recognition')
    test_img = cv2.imread('saved/{}.jpg'.format(always))
    faces_detected, gray_img = fr.faceDetection(test_img)
    speak("I found your data from our system")

    faces, faceID = fr.labels_for_training_data('test')
    face_recognizer = fr.train_classifier(faces, faceID)
    face_recognizer.write('trainingData.yml')

    users_list()

    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)  #predicting the label of given image
        print("Confidence:", confidence)
        print("label:", label)
        fr.draw_rect(test_img, face)
        predicted_name = name[label]
        if (
                confidence > 37
        ):  #If confidence more than 37 then don't print predicted face text on screen
            welcome()
            break
        fr.put_text(test_img, predicted_name, x, y)

    resized_img = cv2.resize(test_img, (1000, 1000))
    cv2.imshow("Face", resized_img)
    cv2.waitKey(0)  #Waits indefinitely until a key is pressed
    cv2.destroyAllWindows
Пример #2
0
def saveDetails(name):

    path = '/home/pi/Desktop/Project3/trainingImages/'
    for i, j, k in os.walk(path):
        number_of_dirs = len(j)
        break
    number_of_dirs += 1
    p1 = '/home/pi/Desktop/Project3/trainingImages/' + str(number_of_dirs)
    os.mkdir(p1)
    #namesAndPath[len(namesAndPath)+1] = name
    #print(namesAndPath)
    print(name + " get ready for 10 pictures to be taken")
    print("Also as you are ready for next shot, please press 's' ")
    for i in range(10):
        j = raw_input("Ready, press 's': ")
        if j == 's':
            take_picture(name, i, number_of_dirs)
        else:
            print("Sorry wrong key is pressed")
            i -= 2

    print("Thanks " + name)
    print("Now classifier is running on the taken images")
    #use for training data if new images are introduced:-
    try:
        faces, faceId = fr.labels_for_training_data(
            '/home/pi/Desktop/Face Recognition/trainingImages')
        face_recognizer = fr.train_classifier(faces, faceId)
        face_recognizer.save('trainingData.yml')
    except:
        print("Something is wrong with the captured Image")
        return
    print("Face classified Successfully")
    return
def train():

    # read time table and class names
    read_tt.read_tt_and_names()
    # making excel template
    excel_template.make_template()

    # This module takes images  stored in disk and performs face recognition
    test_img_name = str(input("image name : "))
    test_img = cv2.imread('TestImages/' + test_img_name +
                          '.jpg')  # test_img path

    # detect all the faces in image
    faces_detected, gray_img = fr.faceDetection(test_img)
    print("faces_detected:", faces_detected)
    # counter for keeping face count
    face_count = len(faces_detected)
    print("face_count:", face_count)

    faces, faceID = fr.labels_for_training_data('trainingImages')
    face_recognizer = fr.train_classifier(faces, faceID)
    # have to store our trained data so we can use it later without going through the training process again
    face_recognizer.write('trainingData.yml')
    # use this .yml file in future to avoid training time

    # creating dictionary containing names for each label
    name = np.load("names.npy", allow_pickle=True, fix_imports=True)
    name = name.item()

    # id of students present in class
    present = []

    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)  # predicting the label of given image
        present.append(label)
        fr.draw_rect(test_img, face)  # drawing rectangle on face
        predicted_name = name[label]
        fr.put_text(test_img, predicted_name, x,
                    y)  # printing name of the person

    # # print ids of present students
    # present.sort()
    print(present)
    # cv2.imshow("test image", resized_img)
    cv2.waitKey(0)  # Waits indefinitely until a key is pressed
    cv2.destroyAllWindows()


# train()
Пример #4
0
def dete():
    def audio():
        my_text = "user found"
        language = 'en'
        myobj = gTTS(text=my_text, lang=language, slow=False)
        myobj.save("welcome.mp3")
        os.system("welcome.mp3")

    test_img = cv2.imread('TestImages/divyanshu.jpg')

    faces_detected, gray_img = fr.faceDetection(test_img)
    print("faces_detected:", faces_detected)

    faces, faceID = fr.labels_for_training_data('trainingImages')
    face_recognizer = fr.train_classifier(faces, faceID)
    face_recognizer.write('trainingData.yml')

    name = {0: "chirag", 1: "divyanshu"}

    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]
        if (confidence > 37):
            continue

        fr.put_text(test_img, predicted_name, x, y)
        audio()

    resized_img = cv2.resize(test_img, (1000, 1000))
    cv2.imshow("face dtecetion ", resized_img)
    cv2.waitKey(0)
    cv2.destroyAllWindows
Пример #5
0
import os

import faceRecognition as fr
print(fr)

test_img = cv2.imread(
    r'C:\Users\Dell\Desktop\Data Science\projects\Face_Recognition\Face-Recognition-master\myphoto.jpg'
)  #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(
    r'C:\Users\Dell\Desktop\Data Science\projects\Face_Recognition\Face-Recognition-master\images'
)  #Give path to the train-images folder which has both labeled folder as 0 and 1
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save(
    r'C:\Users\Dell\Desktop\Data Science\projects\Face_Recognition\Face-Recognition-master\trainingData.yml'
)  #It will save the trained model. Just give path to where you want to save

name = {
    0: "Uday"
}  #Change names accordingly. If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1.

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)
parser = ap.ArgumentParser()
parser.add_argument('-w',
                    '--width',
                    help="width to resize",
                    default=100,
                    type=int)
parser.add_argument('-e',
                    '--height',
                    help="height to resize",
                    default=100,
                    type=int)
parser.add_argument('-a',
                    '--algorithm',
                    help="1-LBPH, 2-Eigenfaces",
                    default=1,
                    type=int)
args = vars(parser.parse_args())

faces, faceID = fr.labels_for_training_data('Dataset/train', args["width"],
                                            args["height"])

if args["algorithm"] == 1:
    face_recognizer = fr.train_classifierLBPH(faces, faceID)
elif args["algorithm"] == 2:
    face_recognizer = fr.train_classifierEigen(faces, faceID)
else:
    print("Option not valid")
    exit(0)

face_recognizer.save("trainingData.yml")
Пример #7
0
import cv2
import os

import faceRecognition as fr
print(fr)

test_img = cv2.imread(r'C:\Python37\Projects\Face Recognition\1.jpg'
                      )  #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(
    r'Give Path Here\train-images'
)  #Give path to the train-images folder which has both labeled folder as 0 and 1
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save(
    r'Give Path Here\trainingData.yml'
)  #It will save the trained model. Just give path to where you want to save

name = {
    0: "Ashish",
    1: "Vijay Deverakonda"
}  #Change names accordingly. If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1.

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)
Пример #8
0
import numpy as np
import cv2
import os

import faceRecognition as fr
print (fr)

test_img=cv2.imread(r'C:\Users\hp\Downloads\1.jpg')  #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(r'G:\prsnal\Face-Recognition-master\img') #Give path to the train-images folder which has both labeled folder as 0 and 1
face_recognizer=fr.train_classifier(faces,faceID)
face_recognizer.save(r'trainingData.yml') #It will save the trained model. Just give path to where you want to save

name={0:"Mohan",1:"Sanju"}    #Change names accordingly. If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1.


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)
Пример #9
0
import cv2
import os
import numpy as np
import faceRecognition as fr

#This module takes images  stored in disk and performs face recognition
test_img = cv2.imread(
    'E:\ppts\deep learning\FaceRecognition-master\FaceRecognition-master\TestImages\p3.jpg'
)  #test_img path
faces_detected, gray_img = fr.faceDetection(test_img)
print("faces_detected:", faces_detected)

#Comment below lines when running this program second time.Since it saves training.yml file in directory
faces, faceID = fr.labels_for_training_data(
    'E:\ppts\deep learning\FaceRecognition-master\FaceRecognition-master\trainingImages'
)
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.write(
    'E:\ppts\deep learning\FaceRecognition-master\FaceRecognition-master\trainingData.yml'
)

#Uncomment below line for subsequent runs
#face_recognizer=cv2.face.LBPHFaceRecognizer_create()
#face_recognizer.read('E:\ppts\deep learning\FaceRecognition-master\FaceRecognition-master\trainingData.yml')
#use this to #load training data for subsequent runs

name = {
    0: "Priyanka",
    1: "Kangana",
    2: "Mahesh"
}  #creating dictionary containing names for each label
Пример #10
0
import cv2
import os
import numpy as np
import faceRecognition as fr


#This module takes images  stored in diskand performs face recognition
test_img=cv2.imread('Tutorial_faceRecognition/TestImages/neha1.jpg')#test_img path
faces_detected,gray_img=fr.faceDetection(test_img)
print("faces_detected:",faces_detected)


#Comment belows lines when running this program second time.Since it saves training.yml file in directory
faces,faceID=fr.labels_for_training_data('Tutorial_faceRecognition/trainingImages')
face_recognizer=fr.train_classifier(faces,faceID)
face_recognizer.save('trainingData.yml')
face_recognizer=cv2.face.LBPHFaceRecognizer_create()

#Uncomment below line for subsequent runs
# face_recognizer.read('trainingData.yml')#use this to load training data for subsequent runs

name={0:"Priyanka",1:"Neha"}#creating dictionary containing names for each label

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)#predicting the label of given image
    print("confidence:",confidence)
    print("label:",label)
    fr.draw_rect(test_img,face)
    predicted_name=name[label]
Пример #11
0
import numpy as np
import faceRecognition as fr

test_img = cv2.imread('Locate the captured image to be detected')
faces_detected, gray_img = fr.faceDetection(test_img)
print("The detected face:", faces_detected)

for (x, y, w, h) in faces_detected:
    cv2.rectangle(test_img, (x, y), (x + w, y + h), (255, 0, 0), thickness=1)

#resized_img=cv2.resize(test_img,(1000,700))
#cv2.imshow("Internship Project in DDU",resized_img)
#cv2.waitKey(0)
#cv2.destroyAllWindows

faces, faceID = fr.labels_for_training_data(
    'Locate Path of the folder where we train our images')
face_recognizer = fr.train_classifier(faces, faceID)
name = {0: "Unlicenced", 1: "Licenced"}

for face in faces_detected:
    (x, y, w, h) = face
    roi_gray = gray_img[y:y + h, x:x + h]
    lable, confidence = face_recognizer.predict(roi_gray)
    print("confidence:", confidence)
    print("lable:", lable)
    fr.draw_rect(test_img, face)
    predicted_name = name[lable]
    fr.put_text(test_img, predicted_name, x, y)

resized_img = cv2.resize(test_img, (600, 400))
cv2.imshow("Final Project in ASTU", resized_img)
Пример #12
0
import cv2
import os
import numpy as np
import faceRecognition as fr

test_img = cv2.imread('image.jpg')
faces_detected, gray_img = fr.faceDetection(test_img)
print("face-detected:", faces_detected)
#give the position of the rectangle to detect the face
for(x, y, w, h) in faces_detected:
	cv2.rectangle(test_img, (x, y), (x+w, y+h), (255, 0, 0), thickness = 5)


faces, faceID = fr.labels_for_training_data('/media/chaand/New Volume4/Coding/Python/face-recon/training')
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save('trainingData.yml')
#face_recognizer = cv2.face.LBPHFaceRecognizer_create()
face_recognizer.read('/media/chaand/New Volume4/Coding/Python/face-recon/trainingData.yml')
name = { 0: 'Deepika',
	1:'Riley Reid'
}
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]
	if(confidence <37):
		continue
Пример #13
0
import cv2
import os
import numpy as np
import faceRecognition as fr

faces, faceID = fr.labels_for_training_data('Dataset/train')
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save("trainingData.yml")

Пример #14
0
import cv2
import os

import faceRecognition as fr
from user_data import name

test_img = cv2.imread(
    r'C:\\Users\\Bas\\Documents\\College\\Project\\Face-Recognition\\train-images\\0\\image0000.jpg'
)  #Give path to the image which you want to test

faces_detected, gray_img = fr.faceDetection(test_img)
print("face Detected: ", faces_detected)

#Give path to the train-images folder
faces, faceID = fr.labels_for_training_data(
    r'C:\\Users\\Bas\\Documents\\College\\Project\\Face-Recognition\\train-images\\'
)
face_recognizer = fr.train_classifier(faces, faceID)

#It will save the trained model.
face_recognizer.save(
    r'C:\\Users\\Bas\\Documents\\College\\Project\\Face-Recognition\\train-images\\training_data.yml'
)

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)
Пример #15
0
import cv2
import os
import numpy as np
import faceRecognition as fr

#This module takes images  stored in diskand performs face recognition
test_img = cv2.imread('F://face//test_img//rohit.jpg')  #test_img path
faces_detected, gray_img = fr.faceDetection(test_img)
print("faces_detected:", faces_detected)

#Comment belows lines when running this program second time.Since it saves training.yml file in directory
faces, faceID = fr.labels_for_training_data('F://face//training_images')
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.write('F://face//trainingData.yml')

#Uncomment below line for subsequent runs
face_recognizer = cv2.face.LBPHFaceRecognizer_create()
face_recognizer.read(
    'trainingData.yml')  #use this to load training data for subsequent runs

name = {
    0: "Mask on",
    1: "Without mask"
}  #creating dictionary containing names for each label

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)  #predicting the label of given image
    print("confidence:", confidence)
Пример #16
0
test_img = cv2.imread(' ')  #test_img path
faces_detected, gray_img = fr.faceDetection(test_img)
print("faces_detected:", faces_detected)

for (x, y, w, h) in faces_detected:
    cv2.rectangle(test_img, (x, y), (x + w, y + h), (250, 0, 0), thickness=3)

# =============================================================================
# resized_img=cv2.resize(test_img,(600,800))
# 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('trainingimages')
face_recognizer = fr.train_classifier(faces, faceid)
face_recognizer.save('trainingdata.yml')

#Uncomment below line for subsequent runs
# =============================================================================
# face_recognizer=cv2.face.LBPHFaceRecognizer_create()
# face_recognizer.read('trainingdata.yml')
# =============================================================================

name = {
    0: "name1",
    1: "name2"
}  #creating dictionary containing names for each label

for face in faces_detected:
import numpy as np
import cv2
import os

import faceRecognition as fr
print (fr)

test_img=cv2.imread(r'C:\Users\adithya\Face-Recognition\test_image.jpg')  #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(r'C:\Users\adithya\Face-Recognition\train_images') #Give path to the train-images folder which has both labeled folder as 0 and 1
face_recognizer=fr.train_classifier(faces,faceID)
face_recognizer.save(r'C:\Users\adithya\Face-Recognition\trainingData.yml') #It will save the trained model. Just give path to where you want to save

name={0:"Adithya Suresh"}    #Change names accordingly. If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1.


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)
Пример #18
0
print(f"faces_detected : {faces_detected}")

# faces,face_id = fr.labels_for_training_data("/home/avisek/Desktop/FaceRecognition/dataset/training/Batch-2018-2019")
# face_recognizer = fr.train_classifier(faces,face_id)
# face_recognizer.save("trainedModel/Batch-2018-2019.yml")

face_recognizer = cv2.face.LBPHFaceRecognizer_create()
try:
    face_recognizer.read(
        "/home/avisek/Desktop/FaceRecognition/trainedModel/Batch-2018-2019.yml"
    )
except:
    face_recognizer = fr.train_classifier(faces, face_id)
    face_recognizer.save("trainedModel/Batch-2018-2019.yml")
    faces, face_id = fr.labels_for_training_data(
        "/home/avisek/Desktop/FaceRecognition/dataset/training/Batch-2018-2019"
    )

name = {
    35: "Atiab kalam",
    51: "Avisek shaw",
    60: "Agnibesh Mukherjee",
    64: "Abhishek Charan",
    37: "Madhurima Maji",
    32: "Arnab kumar Pati"
}

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)
Пример #19
0
import faceRecognition as fr

print(fr)

test_img = cv2.imread(
    r'C:/Users/balajiam/Documents/ML Data Analysis/Face-Recognition-master/1.jpg'
)

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(
    r'C:/Users/balajiam/Documents/ML Data Analysis/Face-Recognition-master/train-images'
)  #Give path to the train-images folder which has both labeled folder as 0 and 1
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save(
    r'C:/Users/balajiam/Documents/ML Data Analysis/Face-Recognition-master/trainingData.yml'
)  #It will save the trained model. Just give path to where you want to save

name = {0: "Balaji", 1: "Srini"}

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 numpy as np
import faceRecognition as fr

test_img=cv2.imread("test_img.jpg")
faces_Detected,gray_img=fr.faceDetection(test_img)
print("faces_detected:",faces_Detected)

#for (x,y,w,h) in faces_detected:
    #cv2.rectangle(test_img,(x,y),(x+w,y+h),(255,0,0),2)
    
    #resized_img=cv2.resize(test_img,(1000,700))
    #cv2.imshow("face dtecetion",resized_img)
    #cv2.waitKey(0)
    #cv2.destroyAllWindows
    
faces,faceID=fr.labels_for_training_data("C://Users//Mounika Reddy P//Desktop//FACE//trainingimages")
face_recognizer= fr.train_classifier(faces,faceID)
face_recognizer.save('trainingData.yml')
name={0:"Priyanka",1:"Nick"}
    
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)
    
    test_img=cv2.resize(test_img,(1000,1000))
def train(absolutePathModel,list):
   test = os.path.exists(path_of_model)
   if(not test):
       faces,faceID=fr.labels_for_training_data('trainingImages')
       face_recognizer=fr.train_classifier(faces,faceID)
       face_recognizer.write('trainingData.yml')
Пример #22
0
import os
import numpy as np
import faceRecognition as fr
from os import path

#This module takes images  stored in diskand performs face recognition
#print(os.path.dirname(__file__))
filePath = os.path.dirname(__file__)
# print(filePath)

test_img=cv2.imread(filePath +'/TestImages/WIN_20201002_17_13_01_Pro.jpg')#test_img path
faces_detected,gray_img=fr.faceDetection(test_img)
print("faces_detected:",faces_detected)

#Comment belows lines when running this program second time.Since it saves training.yml file in directory
faces,faceID=fr.labels_for_training_data(filePath +'/trainingImages')
face_recognizer=fr.train_classifier(faces,faceID)
face_recognizer.write(filePath +'/trainingData.yml')

#Uncomment below line for subsequent runs
# face_recognizer=cv2.face.LBPHFaceRecognizer_create()
# face_recognizer.read('trainingData.yml')#use this to load training data for subsequent runs

name={1:"Manoj"}#creating dictionary containing names for each label

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)#predicting the label of given image
    print("confidence:",confidence)
    print("label:",label)
Пример #23
0
import os

import faceRecognition as fr
print(fr)

test_img = cv2.imread(
    r'/home/bhanu/PycharmProjects/Face-Recogn/Face-Recognition/1.jpg'
)  #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(
    r'/home/bhanu/PycharmProjects/Face-Recogn/Face-Recognition/train-images'
)  #Give path to the train-images folder which has both labeled folder as 0 and 1
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save(
    r'/home/bhanu/PycharmProjects/Face-Recogn/Face-Recognition/trainingData.yml'
)  #It will save the trained model. Just give path to where you want to save

name = {
    0: "Bhanu"
}  #Change names accordingly. If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1.

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)
Пример #24
0
def training_student():
    faces, faceID = fr.labels_for_training_data(
        '/home/siva_ganesh/zips/projects/AttendanceSystem/static/')
    face_recognizer = fr.train_classifier(faces, faceID)
    face_recognizer.write('trainingData.yml')
Пример #25
0
import numpy as np
import faceRecognition as fr

test_img = cv2.imread("shushkov(0).jpg")
faces_detected, gray_img = fr.faceDetection(test_img)
print("face_detected:", faces_detected)

# for (x, y, w, h) in faces_detected:
#     cv2.rectangle(test_img, (x, y), (x + w, y + h), (255, 0, 0), 5)

# resized_img = cv2.resize(test_img,  (1000, 700))
# cv2.imshow("face detection tutorial", resized_img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

faces, faceID = fr.labels_for_training_data("shushkov(0).jpg")
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save("trainingData.yaml")
name = {0: "Priyanka", 1: "Neha"}

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)

resized_img = cv2.resize(test_img, (1000, 700))
import os

import faceRecognition as fr
print(fr)

test_img = cv2.imread(
    r'C:/Users/SAFI UDDIN/Desktop/face/train-images/0/image0000.jpg'
)  #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(
    r'C:/Users/SAFI UDDIN/Desktop/face/train-images'
)  #Give path to the train-images folder which has both labeled folder as 0 and 1
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save(
    r'C:/Users/SAFI UDDIN/Desktop/face/train-images/trainingData.yml'
)  #It will save the trained model. Just give path to where you want to save

name = {
    0: "unknown",
    1: "Kalam"
}  #Change names accordingly. If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1.

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)
Пример #27
0
import numpy as np
import faceRecognition as fr

test_img=cv2.imread('/Users/duongkhieu/documents/face-recognition/testimages/Tt1.jpg')
faces_detected, gray_img=fr.faceDetection(test_img)
print("faces_detected:", faces_detected)

# for (x, y, w, h) in faces_detected:
#     cv2.rectangle(test_img,(x, y), (x+w, y+h), (255, 0, 0), thickness=5)

# resized_img=cv2.resize(test_img, (1000, 700))
# cv2.imshow("face dtection tutorial", resized_img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

faces, faceID=fr.labels_for_training_data('/Users/duongkhieu/documents/face-recognition/trainingImages')
face_recognizer=fr.train_classifier(faces, faceID)
name={0:"T", 1:"G"}

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)

resized_img=cv2.resize(test_img, (1000, 700))
cv2.imshow("face dtection tutorial", resized_img)
Пример #28
0
import cv2
import os
import numpy as np
import faceRecognition as fr

test_img = cv2.imread(
    'C:\\Users\\swara\\Desktop\\Envision\\FaceRecognition-master\\TestImages\\2.jpg'
)  #test_img path
faces_detected, gray_img = fr.faceDetection(test_img)
print("faces_detected:", faces_detected)

faces, faceID = fr.labels_for_training_data(
    'C:\\Users\\swara\\Desktop\\Envision\\FaceRecognition-master\\trainingImages'
)
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.write('trainingData.yml')

c = 0
name = {
    0: "Akshya RA1711003010111",
    1: "Swaraaj RA1711003010118",
    2: "Devesh RA1711003010116",
    3: "Himanshu RA1711003010131",
    4: "Anish RA1711003010115",
    6: "AbhishiktH RA1711003010128",
    7: "Mouli RA1711003010076"
}
name1 = {
    0: "Actor",
    1: "CSE",
    2: "Studnt",
Пример #29
0
import cv2
import os
import numpy as np
import faceRecognition as fr

#This module takes images  stored in diskand performs face recognition
test_img = cv2.imread('TestImages/kangana.jpg')  #test_img path
faces_detected, gray_img = fr.faceDetection(test_img)
print("faces_detected:", faces_detected)

#Comment belows lines when running this program second time.Since it saves training.yml file in directory
faces, faceID = fr.labels_for_training_data('trainingImages')
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.write('trainingData.yml')

#Uncomment below line for subsequent runs
# face_recognizer=cv2.face.LBPHFaceRecognizer_create()
# face_recognizer.read('trainingData.yml')#use this to load training data for subsequent runs

name = {
    0: "Priyanka",
    1: "Kangana"
}  #creating dictionary containing names for each label

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)  #predicting the label of given image
    print("confidence:", confidence)
    print("label:", label)
Пример #30
0
import cv2
import os

import faceRecognition as fr
print(fr)

test_img = cv2.imread(
    r'C:\Users\A707272\PycharmProjects\Face_Recognition\Test_image\test1.jpg'
)  #Give path to the image which you want to test

faces_detected, gray_img = fr.faceDetection(test_img)
print("face Detected: ", faces_detected)

# Training begins here

faces, faceID = fr.labels_for_training_data(
    r'C:\Users\A707272\PycharmProjects\Face_Recognition\Training_images')
face_recognizer = fr.train_classifier(faces, faceID)
face_recognizer.save(
    r'C:\Users\A707272\PycharmProjects\Face_Recognition\trainingData.yml')

name = {0: "Aniket", 1: " Ramavati"}

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)