Opencv learning notes 05 face detection and recognition attributeerror: module ‘CV2’ has no attribute ‘face’

How did “people you might know” find you on social software>>>

1 environment setting:


python 3.6.8

opencv 4.0.1

2 try the best method

In learning face recognition, there is no face attribute in CV2. I found several methods on the Internet, but failed to solve the problem

2.1 method 1

Source: module ‘CV2. CV2’ has no attribute ‘face’

pip install opencv-contrib-python

Restart sublime and still report an error after running

Of course, this failure may be due to the mismatch between opencv and contrib versions

2.2 method 2

Source: opencv3 Python face recognition method face recognition and tagging



model = cv2.face.createEigenFaceRecognizer()

Change to

model = cv2.face_EigenFaceRecognizer.create()

According to the error report, it just doesn’t exist this time_ The eigenfacerecognizer property

Of course, the above two can not solve the error, it may be a version problem

3 solutions

3.1 find roots and ask ancestors – Official Website

First, check the opencv website

opencv modules stands out

Since there is a problem with the modules of OpenCV, let’s look at the modules directly

note: don’t click modules in the menu bar, just look at the contents of this page; The main reason is that the content you see after clicking is confusing. On the contrary, it doesn’t help much to “open the magic door”

It is not difficult to find that we did not find the face class in the main modules of OpenCV; When we continue to look at extra modules, we find face Ren Du two pulse to get through

It’s really a coincidence. When you open the modules in the menu bar, you will find that all modules (here is a list of all modules:) are listed for up to four pages. Fortunately, face analysis appears on the first page. After clicking it, you will see a detailed explanation of the face class [face analysis]. However, it’s hard to see the true face of Lushan at this time

3.2 solutions

When installing libraries before, I remember that some library files contain contrib, but they have not been installed. Contrib should be related to extra modules

Open the python Extension Pack website ~gohlke/pythonlibs/#opencv,

Find the corresponding version of OpenCV_ python-4.0.1+contrib-cp36-cp36m-win_ Amd64.whl, download install

It’s done

The opencv Python was uninstalled before installation

The installed version is

opencv-python 4.0.1+contrib

4 references

Official website

Face analysis website face.html

How to compile opencv3.0 (including extra modules) is a good and enlightening topic ~Gohlke/pythonlibs/#opencvpython third party library file

Module ‘CV2. CV2’ has no attribute ‘face’ this case is not successful, which may be caused by the mismatch between opencv and extend modules

Opencv3 Python face recognition method – face recognition and tagging document describes the reason. It may be that the new version changes the code form in the book, and the author should also spend a lot of effort

Similar Posts: