求助代码报错'NoneType' object is not subscriptable
from PIL import Image, ImageDraw, ImageFontimport cv2
import os
def draw(pic):
img = cv2.imread('pic/' + pic)
img = img[:, :, (2, 1, 0)]
blank = Image.new("RGB", ), len(img)], "white")
drawObj = ImageDraw.Draw(blank)
n = 10
font = ImageFont.truetype('C:/Windows/Fonts/Microsoft YaHei UI/msyhbd.ttc', size = n - 1)
for i in range(0, len(img), n):
for j in range(0, len(img), n):
text = '武汉加油'
drawObj.ink = img + img * 256 + img * 256 * 256
drawObj.text(, text, font=font)
print('完成处理——', i, j)
blank.save('new/new_' + pic, 'jpeg')
filelist = os.listdir('pic')
for file in filelist:
draw(file)
运行报错
Traceback (most recent call last):
File "D:/PyCharm/PycharmProjects/樱花/cv_3.py", line 28, in <module>
draw(file)
File "D:/PyCharm/PycharmProjects/樱花/cv_3.py", line 7, in draw
img = img[:, :, (2, 1, 0)]
TypeError: 'NoneType' object is not subscriptable
进程已结束,退出代码 1
求助大神应该怎么修改 测试一下img的类型,看看是否能切片
页:
[1]