人脸识别错误,显示所有面孔为未知

问题描述 投票:0回答:0

我正在测试来自 github 的代码以使用面部识别进行考勤,它只有显示已知面孔的代码,然后我添加了一段代码来显示未知面孔..但现在它显示所有面孔都是未知的。

def start(confidence_threshold=0.5):
    if 'face_recognition_model.pkl' not in os.listdir('static'):
        return render_template('home.html',totalreg=totalreg(),datetoday2=datetoday2,mess='There is no trained model in the static folder. Please add a new face to continue.') 

    cap = cv2.VideoCapture(0)
    ret = True
    while ret:
        ret,frame = cap.read()
        if extract_faces(frame)!=():
            (x,y,w,h) = extract_faces(frame)[0]
            cv2.rectangle(frame,(x, y), (x+w, y+h), (255, 0, 20), 2)
            face = cv2.resize(frame[y:y+h,x:x+w], (50, 50))
            result = identify_face(face.reshape(1,-1))
            identified_person = result[0]
            if len(result) > 1 and result[1] > confidence_threshold:
                add_attendance(identified_person)
                cv2.putText(frame,f'{identified_person}',(30,30),cv2.FONT_HERSHEY_SIMPLEX,1,(255, 0, 20),2,cv2.LINE_AA)
            else:
                cv2.putText(frame,"Unknown",(30,30),cv2.FONT_HERSHEY_SIMPLEX,1,(255, 0, 20),2,cv2.LINE_AA)
        cv2.imshow('Attendance',frame)
        if cv2.waitKey(1)==27:
            break
    cap.release()
    cv2.destroyAllWindows()
    names,rolls,times,l = extract_attendance()    
    return render_template('home.html',names=names,rolls=rolls,times=times,l=l,totalreg=totalreg(),datetoday2=datetoday2)

这段代码是识别人脸的,我加了一个阈值,但是没有用。这是我获取示例代码的地方

https://machinelearningprojects.net/face-recognition-based-attendance-system/

python opencv face-recognition knn face-detection
© www.soinside.com 2019 - 2024. All rights reserved.