当前位置: 代码迷 >> 综合 >> 【踩坑记】解决cv2:AttributeError: 'NoneType' object has no attribute 'shape'
  详细解决方案

【踩坑记】解决cv2:AttributeError: 'NoneType' object has no attribute 'shape'

热度:33   发布时间:2024-01-27 19:08:03.0

1. 用cv2读取照片

import json
import cv2
import numpy as np
import os# 照片路径
img_file = "D:\\照片\\1.jpg"# 读取照片
img = cv2.imread(img_file)# 查看照片shape
print('shape: ', img.shape)

 2.报错

Traceback (most recent call last):
File "D:/LocalGithub/Python/untitled/file_mask.py", line 28, in <module>
print('shape: ', img.shape)
AttributeError: 'NoneType' object has no attribute 'shape'

3.问题解决

出现这个问题的主要原因图片路径包含中文,导致cv2没有把图片读取出来,将路径修改为英文即可解决。

  相关解决方案