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.
My Code:
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)
It's giving me this error:
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'
The blackboard has been defined here:
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)
to
draw = ImageDraw.Draw(Image.fromarray(blackboard))
Which give ImageDraw an Image which it can understand not a numpy array which it can't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With