opencv: error resolution: cv2.face.LBPHFaceRecognizer_create() AttributeError: module 'cv2' has no attribute 'face

front nonsense

( You can skip this paragraph directly ): I am really excited, I have been working on this problem for at least two hours. Let me describe this process first. When I learned opencv's face recognition on station b: read pictures, grayscale pictures, modify picture sizes, draw rectangular frames, detect single or multiple faces, and detect faces in videos. When there are no problems with human faces! I'm stuck on the training data . Of course it was done before running pip install opencv-contrib-python, but! Once the program is run, such an error will be generated. recognizer=cv2.face.LBPHFaceRecognizer_create() AttributeError: module 'cv2' has no attribute 'face'The common way is to uninstall, reinstall, uninstall, reinstall, and use the following commands repeatedly, but it doesn't work for me. Then I found some other reasons: the function name has been modified due to version changes, some functions after opencv3.4.4 (not matching python3.9) have patent restrictions, after reading the official opencv documents, I found that cv2 still has a face , does not match the error reported. After reducing the python version (terrible) and configuring the virtual machine (also terrible), I saw a face recognition article using opencv4.5 and above , and tried to install the 4.5.4.58 version of opencv, and finally it worked! ! ! version really ***

win+r cmd administrator:
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-python
pip install opencv-contrib-python
may work for some people, but not for me, others can try

Environment and configuration before error reporting

python 3.9
vscode
opencv-python 4.7.0.72
opencv-contrib-python 4.7.0.72

error message

Statement: recognizer=cv2.face.LBPHFaceRecognizer_create()
Error: AttributeError: module 'cv2' has no attribute 'face'
Error explanation: There is no face module in cv2
Supplement: cv2.face has no attribute 'LBPHFaceRecognizer_create' because the function name has been modified , how to view the function name used by the current version, mentioned below in this article

Solution

win+r cmd 管理员
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-python==4.5.4.58

pip install opencv-contrib-python==4.5.4.58
If the installation is slow, you can add a mirror

pip install opencv-python==4.5.4.58 -i https://pypi.tuna.tsinghua.edu.cn/simple

For pycharm, you can see if there are opencv-contrib and opencv packages in the compiler setting package. It seems that some of them need to manually click the plus sign to add the package.

yeah! I solved it! So happy! ! !
Attached below is how to choose the version and the reading and eating tutorial of the official opencv document:
select the version: https://www.lfd.uci.edu/~gohlke/pythonlibs/
opencv official document address: https://docs.opencv.org/ 4.x/index.html

1. Choose the version you installed
Open https://www.lfd.uci.edu/~gohlke/pythonlibs/, and find
the red box in the OpenCV section, indicating that the opencv version is 4.5.5, corresponding to python version 3.9, and the corresponding environment is windows64 bit.
insert image description here
After selecting the version to download above, open the opencv official website to view the function usage of the corresponding version.
First select the good version at the arrow.
insert image description here
2. Click the location as shown in the figure.
insert image description here
Take the LBPHFaceRecognizer function in the face as an example, find the face and click in, then find the LBPHFaceRecognizer and click in, the page is as follows: insert image description hereslide down, and there will be instructions for use. Take create() as an example, the underlined part is the current version Opencv's function usage method and name, cv2.face has no attribute 'LBPHFaceRecognizer_create'friends who appear, pay attention
insert image description here

ok, problem solved

Guess you like

Origin blog.csdn.net/qq_45788060/article/details/129465724