简体   繁体   中英

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.

在代码的第6行中添加/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM