i am trying to do something like this :
=====================================================
import os
import cv2
from PIL import Image pip install pillow
import numpy as np # pip install numpy
def train_classifier(data_dir):
path = [os.path.join(data_dir, f) for f in os.listdir(data_dir)]
faces = []
ids = []
for image in path:
img = Image.open(image).convert('L')
imageNp = np.array(img, 'uint8')
id = int(os.path.split(image)[1].split(".")[1])
faces.append(imageNp)
ids.append(id)
ids = np.array(ids)
# Train and save classifier
clf = cv2.face.LBPHFaceRecognizer_create()
clf.train(faces,ids)
clf.write("classifier.xml")
train_classifier(âdataâ)
=====================================================
But there is error message coming is like this:
AttributeError Traceback (most recent call last)
Cell In[52], line 26
24 clf.train(faces,ids)
25 clf.write(âclassifier.xmlâ)
â> 26 train_classifier(âdataâ)
Cell In[52], line 23, in train_classifier(data_dir)
20 ids = np.array(ids)
22 # Train and save classifier
â> 23 clf = cv2.face.LBPHFaceRecognizer_create()
24 clf.train(faces,ids)
25 clf.write(âclassifier.xmlâ)
AttributeError: module âcv2â has no attribute âfaceâ
=====================================================
I have opencv version of 4.9.0
and I have tried uninstalling and then again installing opencv but nothing worked for me!
what should I do now?