I am creating a face recognition system using Python and OpenCV on these versions:
When I try to train the face recognizer:
face_recognizer = cv2.face.createLBPHFaceRecognizer()
I get this error:
AttributeError: module 'cv2' has no attribute 'face'
Update:
I've tried to do this:
pip install opencv_python‑3.3.0+contrib‑cp36‑cp36m‑win_amd64.whl
Also:
conda install -c menpo opencv3=3.3.0
And I still have the error.
The Menpo project does not have an installer for OpenCV 3.3. The Menpo project is up to 3.1 on macOS and Windows, and 3.2 on Linux. See the Anaconda package for that description and also the list of files for the installer versions. Actually, you can check out the GitHub repo for Menpo's OpenCV3 build and grab the files yourself. You can change the build files to suit your system if needed.
I'm not sure if your pip
attempt includes a typo or not---the correct PyPI package wheel
file with the contrib module is opencv_contrib_python
not opencv_python+contrib
, as shown at PyPI. Note that if you're not using Windows the GUI features of OpenCV will not work with the pip
installer, including imshow()
and other similar features.
You'd be better served just removing and reinstalling fresh with the contrib modules instead of trying to build them in later.
While I was looking for the same solution, I tried out many methods which don't work well with successfully installing OpenCV along with the extra modules i.e., OpenCV Contrib.
Apparently, while using pip install opencv-python
windows platforms usually download only OpenCV without the extra modules!
What works, is stable and easy to install:
pip install <whl filename>
I have tried other methods which are unreliable such as the solution suggested by @RoyaumeIX, however ended up with failure.
So is it with using
pip install opencv
pip install opencv-contrib
Installing opencv-contrib
does not properly register the opencv
package.
I strongly suggest that you directly download the official whl file and install it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With