thisbejim / Pyrebase

A simple python wrapper for the Firebase API.
2.05k stars 526 forks source link

please help #351

Open noobcoder235 opened 4 years ago

noobcoder235 commented 4 years ago

so this is the code..

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

recognizer = cv2.face.LBPHFaceRecognizer_create() detector= cv2.CascadeClassifier("haarcascade_frontalface_default.xml");

def getImagesAndLabels(path):

imagePaths=[os.path.join(path,f) for f in os.listdir(path)]

faceSamples=[]

Ids=[]

for imagePath in imagePaths:

    pilImage=Image.open(imagePath).convert('L')

    imageNp=np.array(pilImage,'uint8')

    Id=int(os.path.split(imagePath)[-1].split(".")[1])

    faces=detector.detectMultiScale(imageNp)

    for (x,y,w,h) in faces:
        faceSamples.append(imageNp[y:y+h,x:x+w])
        Ids.append(Id)
return faceSamples,Ids

faces,Ids = getImagesAndLabels('dataSet') s = recognizer.train(faces, np.array(Ids)) print("Successfully trained") recognizer.write('trainer/trainer.yml')

and when i run it i get this error

Traceback (most recent call last):

File "D:\Face-react\Face Recogonition\Test 7\Face-Recognition-Attendance-System-master\attendance\training_dataSet.py", line 32, in s = recognizer.train(faces, np.array(Ids)) cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv_contrib\modules\face\src\lbph_faces.cpp:362: error: (-210:Unsupported format or combination of formats) Empty training data was given. You'll need more than one sample to learn a model. in function 'cv::face::LBPH::train'