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没有把图片读取出来,将路径修改为英文即可解决。