attributeerror: module 'cv2.face' has no attribute 'createlbphfacerecognizer'

蹲街弑〆低调 提交于 2019-12-04 09:05:56
Peter

Had the same problem. Use:

recognizer = cv2.face.LBPHFaceRecognizer_create()

It worked for my program.

There are some missing modules for contributed libraries in the default pip install opencv-python so you need pip install opencv-contrib-python

Under Windows 7, I was able to resolve the issue by simply uninstalling and re-installing opencv:

pip uninstall opencv-contrib-python
pip install opencv-contrib-python

The recogniser is called by:

recognizer = cv2.face.LBPHFaceRecognizer_create()

Try to update your opencv by "python -m pip install opencv-contrib-python" ps: you have to delete the CV2 repository from the Python rep and then run this command (in the CMD windows) if it doesn't work

Try to use this:

import cv2
import os
import numpy as np
from PIL import Image

# Path for face image database
path = 'dataset'
recognizer = cv2.face_LBPHFaceRecognizer.create()
detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

You are using Opencv 3.x, in the new version few modules has been removed. You have two options: 1. Add opencv_contrib module to your existing opencv 3.x version. Here's the link https://github.com/opencv/opencv_contrib 2.you can use older versions of Opencv. Like opencv 2.4.x

open cmd , then --> pip install opencv-contrib-python

I had this problem running opencv Version 3.4.1. Here is what I did.

SPECS: Raspberry pi 3B, OS: Raspbian, Version: 9 (Stretch), Python 3, opencv Version 3.4.1

Check opencv version in python

import cv2

cv2.__version__

1) sudo pip install opencv-contrib-python

*After this I could not import cv2 in python until I installed the following.

2) sudo apt-get update

3) sudo apt-get install libhdf5-dev

4) sudo apt-get update

5) sudo apt-get install libhdf5-serial-dev libqtgui4 libqt4-test

I fixed this issue with two commands:

First: sudo pip3 uninstall opencv-contrib-python

Second: sudo python3 -m pip install opencv-contrib-python==3.3.0.9

This fixed my issues. Hope it helps somebody! Also, if you are using python2, replace “pip3” with “pip” and “python3” with “python”

I fixed this issue by installing: sudo pip install opencv-contrib-python.

Then look for correct format.

python2 is default

Basically the problem is that python3 and python2 have different format of code.

recognizer = cv2.face.LBPHFaceRecognizer_create()

This is the format of python2.

recognizer = cv2.face.createLBPHFaceRecognizer()

This is the format of python3

Even I had this problem when I ran the code using Jupyter Notebook. If you are running it on Jupyter Notebook , then download it as pyhton(.py) file and try to run it in Anaconda Prompt or Command Prompt. This solved the problem for me. Thank You.

  • Uninstall this package (opencv-python) by command :-
  • pip uninstall opencv-python
  • Install the library opencv-contrib python using command :-
  • pip install opencv-contrib-python
  • then add or check :-
  • recognizer = cv2.face_LBPHFaceRecognizer.create()
  • It will work fine
  • The problem was in opencv-python library cv2.face is not present so it shows attribute missing problem, so install new lib by uninstalling previous one if installed..
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!