好吧,所以我试图为手势识别系统添加印度/尼泊尔字体,并且在Pillow库中苦苦挣扎。我遵循了枕头的文档,并且遇到了AttributeError。
我的代码:
def put_splitted_text_in_blackboard(blackboard, splitted_text):
draw = ImageDraw.Draw(blackboard)
for text in splitted_text:
fonts = ImageFont.truetype("preeti.TTF", 50)
draw.text((10, 25), text, font=fonts)
这给了我这个错误:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\PIL\ImageDraw.py", line
289, in Draw
return im.getdraw(mode)
AttributeError: 'numpy.ndarray' object has no attribute 'getdraw'
黑板在这里定义:
def recognize()
blackboard = np.zeros((480, 640, 3), dtype=np.uint8)
splitted_text = split_sentence(text, 2)
put_splitted_text_in_blackboard(blackboard, splitted_text)
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
res = np.hstack((img, blackboard))
cv2.imshow("Recognizing gesture", res)
cv2.imshow("thresh", thresh)
if cv2.waitKey(1) == ord('q'):
break
有人知道哪里出了问题吗?
最佳答案
您需要做的是更改此行:
draw = ImageDraw.Draw(blackboard)
至
draw = ImageDraw.Draw(Image.fromarray(blackboard))
这给ImageDraw一个它不能理解的图像,而不是一个不能理解的numpy数组。