th3gr3yman
th3gr3yman

Reputation: 21

OpenCV-python Train-LBPH recognizer

I'm writing a face recognizer in python but I'm in trouble with the training part.

import cv2
import numpy as np
from os import listdir
from os.path import isfile, join

data_path = '/home/pi/Desktop/data'
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path, f))]


Training_Data, Labels = [],[]


for i, files in enumerate(onlyfiles):
        image_path = data_path + onlyfiles[i]
        print(image_path)
        images = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
        Training_Data.append(np.asarray(images, dtype=np.uint8))
        Labels.append(i)

Labels = np.asarray(Labels, dtype=np.int32)

model = cv2.createLBPHFaceRecognizer()

model.train( np.asarray(Training_Data) ,np.asarray(Labels) )
print("done")

When I run it I get this error:

Traceback (most recent call last): File "Train_Model.py", line 17, in Training_Data.append(np.asarray(images, dtype=np.uint8)) File "/usr/lib/python2.7/dist-packages/numpy/core/numeric.py", line 460, in asarray return array(a, dtype, copy=False, order=order) TypeError: long() argument must be a string or a number, not 'NoneType'

Thank you.

Upvotes: 1

Views: 1248

Answers (2)

Prajyot Patil
Prajyot Patil

Reputation: 11

i got same problem , and i solved this. when you run

onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path, f))] 

this command that time add another thumb img at position 0.

so we add new command

onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path, f))]
onlyfiles = onlyfiles [1:]

it means we ignore 1st image

it's running

Upvotes: 0

Himal Rawat
Himal Rawat

Reputation: 11

Add / in line number 6 of your code.

(data_path = '/home/pi/Desktop/data/')

Upvotes: 1

Related Questions