Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
def testerAuthorization():
    # This module takes images  stored in disk and 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')
    faces, faceID = fr.labels_for_training_data2()
    face_recognizer = fr.train_classifier(faces, faceID)
    face_recognizer.write('trainingData.yml')
    return True
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()
Exemplo n.º 5
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
Exemplo n.º 6
0
faces_detected, gray_img = fr.faceDetection(test_img)
print("faces_detected:", faces_detected)

# Comment lines 17-34 after 1st run
faces, faceID = None, None
if sys.argv[2] == "2":
    faces, faceID = fr.getFaces('./trainingImages2/')
elif sys.argv[2] == "3":
    faces, faceID = fr.getFaces('./trainingImages3/')
elif sys.argv[2] == "4":
    faces, faceID = fr.getFaces('./trainingImages4/')
else:
    print("Number of types of images should be 2/3/4")
    exit(0)

face_recognizer = fr.train_classifier(faces, faceID)
if sys.argv[2] == "2":
    face_recognizer.write('./trainingData2.yml')
elif sys.argv[2] == "3":
    face_recognizer.write('./trainingData3.yml')
else:
    face_recognizer.write('./trainingData4.yml')

# Uncomment lines 37-43 for subsequent runs
# face_recognizer=cv2.face.LBPHFaceRecognizer_create()
# if sys.argv[2] == "2":
# 	face_recognizer.read('trainingData2.yml')
# elif sys.argv[2] == "3":
# 	face_recognizer.read('trainingData3.yml')
# else :
# 	face_recognizer.read('trainingData4.yml')
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')
Exemplo n.º 8
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')