AttributeError: module cv2.face has no attribute 'createEigenFaceRecognizer'

python3.x中用opecv3做人脸识别有两种模块找不到的报错解决方法。

第一种报错:说cv2中没有face
AttributeError: module ‘cv2’ has no attribute ‘face’
第二种报错:有face,但说face中没有 ‘createEigenFaceRecognizer’
AttributeError: module ‘cv2.face’ has no attribute ‘createEigenFaceRecognizer’

第一个报错是因为没有安装或没有正确安装opencv_contribute模块,仅安装了 opencv主部件。安装即可。

https://pypi.org/project/opencv-contrib-python/#description

这里写图片描述
第二个报错则是因为模块里面的方法名可能有更改,可能打开上图的opencv文档查看正确方法名即可解决。
https://docs.opencv.org/master/dd/d7c/classcv_1_1face_1_1EigenFaceRecognizer.html

这里写图片描述