对于此代码,
import cv2
import numpy as np
from os import listdir
from os.path import isfile, join
data_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'
问题来源:stackoverflow
您可以将整个列表转换为整数。为了解决这个问题,您首先必须将列表转换为字符串,然后再将该字符串转换为整数。由于列表中有多个元素,因此python不知道要传递或转换列表中的哪个元素。
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。