AttributeError: 'module' object has no attribute 'face' error even after installing opencv-contrib

python raise attributeerror
how to handle attribute error in python
how to remove attribute error in python
python attributeerror object has no attribute
attributeerror django
python custom exception
<class 'attributeerror'>
attributeerror pplayoutblank

I was trying to implement a face recognition using Python, OpenCv2 and LBPH (Which is downloaded from HERE)

My python version is 2.7.14 PIP version is 9.0.3 and OpenCV version is 3.4.0

and my code is

import cv2
import numpy as np
import NameFind

# --- import the Haar cascades for face and eye ditection
face_cascade = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml')
eye_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye.xml')
spec_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye_tree_eyeglasses.xml')

help(cv2.face)
# FACE RECOGNISER OBJECT
LBPH = cv2.face.LBPHFaceRecognizer_create(2, 2, 7, 7, 20)
EIGEN = cv2.face.createEigenFaceRecognizer(10, 5000)
FISHER = cv2.face.createFisherFaceRecognizer(5, 500)

# Load the training data from the trainer to recognise the faces
LBPH.load("Recogniser/trainingDataLBPH.xml")
EIGEN.load("Recogniser/trainingDataEigan.xml")
FISHER.load("Recogniser/trainingDataFisher.xml")

# ------------------------------------  PHOTO INPUT  -----------------------------------------------------

img = cv2.imread('Me4.jpg')                  # ------->>> THE ADDRESS TO THE PHOTO

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)                # Convert the Camera to gray
faces = face_cascade.detectMultiScale(gray, 1.3, 4)         # Detect the faces and store the positions
print(faces)

for (x, y, w, h) in faces:                                  # Frames  LOCATION X, Y  WIDTH, HEIGHT

    Face = cv2.resize((gray[y: y+h, x: x+w]), (110, 110))   # The Face is isolated and cropped

    ID, conf = LBPH.predict(Face)                           # LBPH RECOGNITION
    print ID
    NAME = NameFind.ID2Name(ID, conf)
    NameFind.DispID(x, y, w, h, NAME, gray)

    ID, conf = EIGEN.predict(Face)                          # EIGEN FACE RECOGNITION
    NAME = NameFind.ID2Name(ID, conf)
    NameFind.DispID3(x, y, w, h, NAME, gray)

    ID, conf = FISHER.predict(Face)                         # FISHER FACE RECOGNITION
    NAME = NameFind.ID2Name(ID, conf)
    NameFind.DispID2(x, y, w, h, NAME, gray)

cv2.imshow('LBPH Face Recognition System', gray)           # IMAGE DISPLAY
cv2.waitKey(0)
cv2.destroyAllWindows()

I'm getting This error when i run any face recognition files like Recogniser_Image_All_Algorithms.py

Traceback (most recent call last): File "Recogniser_Image_All_Algorithms.py", line 11, in LBPH = cv2.face.LBPHFaceRecognizer_create(2, 2, 7, 7, 20) AttributeError: 'module' object has no attribute 'face'

I've googled the error and found the same answers like THIS ONE

after checking those feeds i tried to install opencv-contrib using python -m pip install opencv-contrib-python

it says

Requirement already satisfied: opencv-contrib-python in c:\users\rak\anaconda3\lib\site-packages Requirement already satisfied: numpy>=1.11.3 in c:\users\rak\anaconda3\lib\site-packages (from opencv-contrib-python)

but the error remains same, how to fix this error. plz help

I have installed opencv for python using sudo apt install python-opencv & received error "AttributeError: 'module' object has no attribute 'face'". My system configuration is OS Ubuntu 16.04 LTS & Python 2.7.12. I used following command to resolve the issue: sudo apt remove python-opencv And installed same library using pip sudo pip install opencv-contrib-python

Now opencv is working absolutely fine.

6. Built-in Exceptions, The following exceptions are the exceptions that are actually raised. exception AssertionError ¶. Raised when an assert statement fails. exception AttributeError ¶. The AttributeError in Python is raised when an invalid attribute reference is made, or when an attribute assignment fails. While most objects support attributes, those that do not will merely raise a TypeError when an attribute access attempt is made.

I find out the problem myself! The problem was I had opencv-python installed, i uninstalled opencv-python and ran pip install opencv-contrib-python it worked.

Thanks for Downvoting the question for no reason even without telling me what I did wrong, without a comment or reply

Python Exception Handling - AttributeError, The AttributeError in Python is raised when an invalid attribute reference is made, or when an attribute assignment fails. While most objects  @desertnaut frankly, this question is 2 months old and I forgot it long time ago :). Sometimes I visit so many questions that I don't remeber questions from previous hour :) – furas 2 days ago

In my Rpi python version is 3.5 and 2.7 both. opencv version is 3.3.0 to change python platform from 2.7.x to 3.5.x... go to program /python idle/ properties,desktop entry / browse/ select idle-python3.5 in face recognition module has no attribute "face". after changing python platform this problem will be solve.

Python: AttributeError, These errors yields to the program not executed. One of the error in Python mostly occurs is “ AttributeError “. AttributeError can be defined as an error that is raised  I usually think about attributes as nouns that belong to an object. For example, “the student has two eyes ”. But in Python, an attribute can also be an action that an object can perform—“The cat can jump ”. An attribute in Python means some property that is associated with a particular type of object.

recognizer = cv2.createLBPHFaceRecognizer()

try this out

Error Encyclopedia, in Python is raised when an invalid attribute reference is made, or when an attribute assignment fails. While most objects support attributes, those that do not will merely raise a TypeError when an attribute access attempt is made. I ran into this problem when I checked out an older version of a repository from git. Git replaced my .py files, but left the untracked .pyc files. Since the .py files and .pyc files were out of sync, the import command in a .py file could not find the corresponding module in the .pyc files.

Built-in Exceptions in Python, Attribute Error. Attributes in Python. I usually think about attributes as nouns that belong to an object. For example, “the student has two eyes”. But in Python, an  AttributeError: module 'tensorflow' has no attribute 'Summary' #9. palunel opened this issue Apr 23, 2019 · 1 comment Comments. Copy link Quote reply

Error Encyclopedia, This happens because the scipy module doesn't have any attribute named sparse . That attribute only gets defined when you import  AttributeError: 'Model' object has no attribute '_get_distribution_strategy' #1239. Open milansoliya4210 opened this issue Dec 24, 2019 · 7 comments Open

Why does this AttributeError in python occur?, When you get an attribute error in Python, it means you tried to access the attribute value of, or assign an attribute value to, a Python object or class instance in  Concrete exceptions¶ The following exceptions are the exceptions that are usually raised. exception AssertionError¶ Raised when an assert statement fails. exception AttributeError¶ Raised when an attribute reference (see Attribute references) or assignment fails.

Comments
  • yeah. I searched for this answer. I couldn't find any answer which explains what is happening. everyone says install opencv contrib but it was showing requirement satisfied. so did some digging n find out the prob. tysm