sudarshan regmi
sudarshan regmi

Reputation: 21

why this error arises though i have install all the required package for opencv?

I have been working on this code for long time , I had run in several ide but all shows same error and i am bit confuse now and i need a proper solution so that code may works

import os
import cv2 as cv
import numpy as np
people=['emily','emma','jim parson']
haar_cas=cv.CascadeClassifier('haar_face.xml')
DIR=r'G:\opencv\faces'
features=[]
labels=[]
def train_face():
    for person in people:
        paths=os.path.join(DIR,person)
        label=people.index(person)
        for img in os.listdir(paths):
            img_path=os.path.join(paths,img)
            img_array=cv.imread(img_path)
            gray=cv.cvtColor(img_array,cv.COLOR_BGR2GRAY)
            faces_rect=haar_cas.detectMultiScale(gray,1.1,2)
            for(x,y,w,h) in faces_rect:
                faces_roi= gray[y:y+h,x:x+w]
                features.append(faces_roi)
                labels.append(label)
train_face()
feature=np.array(features,dtype='object')
label=np.array(labels)

# print(f'length of the feature={len(features)}')
# print(f'lenght of the labels={len(labels)}')
face_reconizer=cv.face.LBPHFaceReconizer_create()
np.save('feature.npy',feature)
np.save('label.py',label)

the output of the code is

File "G:\opencv\face_reconization.py", line 28, in <module>
    face_reconizer=cv.face.LBPHFaceReconizer_create()
AttributeError: module 'cv2.face' has no attribute 'LBPHFaceReconizer_create'

Upvotes: 0

Views: 38

Answers (1)

Shrey Joshi
Shrey Joshi

Reputation: 1206

If you installed opencv by running pip install opencv-python there are some missing packages there so you need to run pip install opencv-contrib-python to install the full version.

If that doesn't work try reinstalling opencv pip3 uninstall opencv-contrib-python python -m pip install opencv-contrib-python

Upvotes: 1

Related Questions