测试处理图片报错
AttributeError: ‘NoneType’ object has no attribute ‘astype’
寻找解决方案1
参考此篇博文,然后可能是下载下来的照片的文件后缀名和文件本身的属性不匹配,所以又重新处理照片一遍
https://blog.csdn.net/weixin_43826242/article/details/90325955
#Attribute Error: 'NoneType' object has no attribute 'astype'
#将所有的图片转换成为jpg格式(防止因为图片格式造成的cv2.imread()异常)
#所有的照片虽然都是.jpg格式的,但是有的照片没有进行转码,只是更改了后缀,因此在模型加载的时候才会报错,可以使用PIL工具将所有的jpg图片转换成为jpg图片,从而避免这样的麻烦
#参考博文https://blog.csdn.net/weixin_43826242/article/details/90325955
import PIL.Image as Image
import os
path='D:/test_img'
def start(Path):
filelist = os.listdir(Path)
for file in filelist:
img = Image.open(Path + '/'+file).convert('RGB')
print(img)
print(file)
img.save('D:/test_pic/'+file)
print('Done!')
start(path)
然鹅还是报错,风暴哭泣!!!
寻找解决方案2
参考此篇博文,修改了路径
https://blog.csdn.net/junyilao/article/details/83502050
原来是:
for allDir in pathDir: # 遍历文件夹
path = r'D:\test_img'+ allDir
pic_name = allDir # 图片名称
image=cv2.imread(path)
修改后
下面展示一些 内联代码片
。
for allDir in pathDir: # 遍历文件夹
path = r'D:\test_img\\' + allDir
pic_name = allDir # 图片名称
image=cv2.imread(path)
综上,就是多了一个斜杠\
我的猪脑子到底值几两呦!!!