Closed hanifizzudinrahman closed 3 years ago
I have this error, and I can't resolve this issue This is the program
import os import cv2 as cv import numpy as np #people = ['...','....'] people = [] for i in os.listdir(r'C:\Users\owner\_Learning_\_Computer Vision - OpenCV_\OpenCV - Python\OpenCV Course - Full Tutorial with Python - YouTube\Resources\Faces\train'): people.append(i) print(people) DIR = r'C:\Users\owner\_Learning_\_Computer Vision - OpenCV_\OpenCV - Python\OpenCV Course - Full Tutorial with Python - YouTube\Resources\Faces\train' features = [] labels = [] haar_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') def create_train(): for person in people: print("Person:", person) path = os.path.join(DIR, person) label = people.index(person) #print("Label:", label) for img in os.listdir(path): img_path = os.path.join(path,img) #print("img_path:", img_path) img_array = cv.imread(img_path) gray = cv.cvtColor(img_array, cv.COLOR_BGR2GRAY) faces_rect = haar_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=4) for (x,y,w,h) in faces_rect: faces_roi = gray[y:y+h, x:x+w] features.append(faces_roi) labels.append(label) #cv.imshow(img, faces_roi) create_train() print('Training Done-------------') #print(f'length of features = {len(features)}') #print(f'length of labels = {len(labels)}') features = np.array(features, dtype='object') labels = np.array(labels) face_recognizer = cv.face.LBPHFaceRecognizer_create() #train face_recognizer.train(features, labels) face_recognizer.save('3.2_face_trained.yml') np.save('3.2_features.py', features) np.save('3.2_labels.py', labels) cv.waitKey(0) cv.destroyAllWindows()
Okay, I've found a couple of potential fixes:
Let me know if this fixes your issue
Closing this now as there hasn't been any reply to this thread. Feel free to reopen it if need be
I have this error, and I can't resolve this issue This is the program