AttributeError: 'NoneType' object has no attribute 'shape'解决方案

AttributeError: ‘NoneType’ object has no attribute 'shape’解决方案

在使用OpenCV处理图片时,比如笔者在书写下列代码时:

cv_img = cv2.imread(dataset_root_path + "total/" + filestr + "/img.png")
self.add_image("shapes", image_id=i, path=img_floder + "/" + imglist[i],
                               width=cv_img.shape[1], height=cv_img.shape[0], mask_path=mask_path, yaml_path=yaml_path)

提示笔者:

AttributeError: 'NoneType' object has no attribute 'shape'

问题分析:
这个原因是因为找不到这个cv_img 图片。
解决方案:
有可能您出现的问题是处在一个循环中,那么找出来的话,可以参考使用抛出异常,具体如下:

cv_img = cv2.imread(dataset_root_path + "total/" + filestr + "/img.png")
try:
	self.add_image("shapes", image_id=i, path=img_floder + "/" + imglist[i],
                               width=cv_img.shape[1], height=cv_img.shape[0], mask_path=mask_path, yaml_path=yaml_path)
except:
    print(dataset_root_path + "total/" + filestr + "/img.png")

那么抛出来的路径,追进去看看,你会发现你的名字可能写错了,总之他找不到了~~~~改了让他找到就行了。

评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值