python#AttributeError: ‘NoneType‘ object has no attribute ‘astype‘ 麻烦检查路径

测试处理图片报错

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)


综上,就是多了一个斜杠\
我的猪脑子到底值几两呦!!!

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值