error: (-2:Unspecified error) File can't be opened for writing! in function 'cv::face::FaceRecognizer::write'

created at 07-31-2021 views: 4

problem

code

recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.train(faces, np.array(ids))
recognizer.write(r'face_trainer\trainer.yml')

I read most of the Internet writes like this, but it always reports

error: (-2:Unspecified error) File can't be opened for writing! in function 'cv::face::FaceRecognizer::write'

solution

It should be impossible to create the face_trainer\trainer.yml file. I suggest you check if there is a face_trainer directory in your current directory, if not, create one manually.

also two points to be noted:

  • try change write to save
  • avoid non-English path
created at:07-31-2021
edited at: 07-31-2021: