对于这段代码,
import cv2import numpy as npfrom os import listdirfrom os.path import isfile, joindata_path = 'dataset/'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] 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.face.LBPHFaceRecognizer_create()model.train(np.asarray(Training_Data), np.asarray(Labels))print("Model Training Completed!!!!!")
我遇到了这个错误
/usr/local/bin/python3.7 "/Users/mac/Google Drive/Read&Write2Database/knowledgeShelfPart-2.py"Traceback (most recent call last): File "/Users/mac/Google Drive/Read&Write2Database/knowledgeShelfPart-2.py", line 14, in <module> Training_Data.append(np.asarray(images, dtype=np.uint8)) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/numeric.py", line 492, in asarray return array(a, dtype, copy=False, order=order)TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
回答:
你不能将整个列表转换为整数。为了解决这个问题,你首先必须将列表转换为字符串,然后再将该字符串转换为整数。由于你的列表中有多个元素,Python不知道你想传递或转换列表中的哪个元素。