我正在从目录中读取图像,当我遍历文件名时,我得到了标题中提到的错误。变量“imagePath”是我本地机器中图像的路径。当 'np.fromfile(imagePath)' 被删除时,代码运行,它甚至会打印图像的路径,但是当我尝试用 numpy 读取它们时会爆炸。
def getTrainingDataFromFile():
for subdir, dirs, images in os.walk(directory):
for sub, dirs, images in os.walk(subdir):
for currentImage in images:
imagePath = str(os.getcwd() + "/" + sub.replace("./", "") + "/" + currentImage)
if '.jpg' in imagePath:
face = np.fromfile(imagePath)
images.append(face)
TypeError Traceback(最近一次调用最后一次)
<ipython-input-8-ce35c0ab49e6> in <module>()
----> 1 getTrainingDataFromFile()
<ipython-input-7-ae9589186aa3> in getTrainingDataFromFile()
16 for sub, dirs, images in os.walk(subdir):
17 for currentImage in images:
---> 18 thisImage = str(os.getcwd() + "/" + sub.replace("./", "") + "/" + currentImage)
19 if '.jpg' in thisImage:
20 face = np.fromfile(thisImage,dtype=np.uint8)
TypeError: ufunc 'add' 不包含签名匹配类型 dtype('