Esempio n. 1
0
def button1():
    ref, frame = capture.read()
    cv2.imwrite(tempimagepath, frame)
    face_img = cv2.imread("test_data/face.jpg")
    # cv2.imshow("Training on image...", face_img)
    try:
        label, rect = face_recognition.rec(face_img)
        print(label)
        if label[1] < 50:
            face_recognition.draw_rectangle(face_img, rect)
            face_recognition.draw_text(face_img,
                                       face_recognition.subjects[label[0]],
                                       rect[0], rect[1] - 5)
            cv2.imshow("welcome", face_img)
            messagebox.showinfo(title='欢迎',
                                message='hi    ' +
                                face_recognition.subjects[label[0]])
        else:
            messagebox.showwarning(title='警告', message='未识别到人脸或用户不存在')
    except BaseException:
        messagebox.showwarning(title='警告', message='未识别到人脸或用户不存在')
Esempio n. 2
0
cap = cv2.VideoCapture(
    0
)  # If you want to recognise face from a video then replace 0 with video path

name = {
    0: "Denio",
}  # Change names accordingly.  If you want to recognize only one person then write:- name={0:"name"} thats all. Dont write for id number 1.
while True:
    ret, test_img = cap.read()
    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), (0, 255, 0),
                      thickness=5)

    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_rectangle(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 detection ", resized_img)
    if cv2.waitKey(10) == ord("q"):
        break