AttributeError:"numpy.ndarray"对象没有属性"getdraw" [英] AttributeError: 'numpy.ndarray' object has no attribute 'getdraw'

查看:291
本文介绍了AttributeError:"numpy.ndarray"对象没有属性"getdraw"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我试图为手势识别系统添加印度/尼泊尔字体,并且我在Pillow库中苦苦挣扎.我遵循了枕头的文档,并且遇到了AttributeError.

Okay so i'm trying to add an indian/nepali font for a gesture recognition system and i'm struggling a bit with the Pillow library. I followed the documentation for pillow and i'm getting an 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

有人知道哪里出了问题吗?

Anyone know where it went wrong?

推荐答案

您需要做的是更改此行:

What you need to do is change this line:

draw = ImageDraw.Draw(blackboard)

draw = ImageDraw.Draw(Image.fromarray(blackboard))

为ImageDraw提供了一个它不能理解的图像,而不是一个不能理解的numpy数组.

Which give ImageDraw an Image which it can understand not a numpy array which it can't.

这篇关于AttributeError:"numpy.ndarray"对象没有属性"getdraw"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆