Search code examples
pythonface-recognition

Face recognition return type issue


I am using face recognition and the code is working fine but when I stop the code it gives the following error.

Traceback (most recent call last):
  File "E:\FYP(STUDENT)\STUDENT\Main.py", line 73, in <module>
    encodecurFrame = face_recognition.face_encodings(imgS, facedetectionFrame)
  File "E:\FYP(STUDENT)\STUDENT\lib\site-packages\face_recognition\api.py", line 214, in face_encodings
    return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]
  File "E:\FYP(STUDENT)\STUDENT\lib\site-packages\face_recognition\api.py", line 214, in <listcomp>
    return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]
KeyboardInterrupt

And This is the line 73

    while True:
        success, img = cap.read()
        imgS = cv2.resize(img,(0,0),None, 0.25, 0.25)
        imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
    
        facedetectionFrame = face_recognition.face_locations(imgS)
  73 -> encodecurFrame = face_recognition.face_encodings(imgS, facedetectionFrame)

Can you guys tell me what the problem could be and how it can be resolved


Solution

  • It is not an error. It says that you are manually stopping the code or the code is being stopped from its Normal Flow. You can use this code and by pressing q the code will stop:

    while True:
    
        success, img = cap.read()
        imgS = cv2.resize(img,(0,0),None, 0.25, 0.25)
        imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
    
        facedetectionFrame = face_recognition.face_locations(imgS)
        encodecurFrame = face_recognition.face_encodings(imgS, facedetectionFrame)
    
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break