I am creating a sign language detection application in Armenian. However, the Armenian letters don't show when I am signing but do show in my console/terminal. What am I doing wrong with my code that is not working. Let me know how can I change or implement to show the letter on the screen. Currently any non-ascii characters display as ?????
or boxes instead of the actual character or symbol like this
How do I show non-ascii characters/text instead of ??
using OpenCV's putText()
method?
PS: I even try implementing using PIL but no luck. Thanks for your help in advance.
Also, when I use unicode_font instead of cv2.QT_FONT_NORMAL
I get an error when I sign as:
Argument 'fontFace' is required to be an integer
Here is my code:
dict_letter = {0: 'Ա', 1: 'Բ', 2: 'Գ', 3: 'Դ', 4: 'Ե', 5: 'Զ', 6: 'Է', 7: 'Ը', 8: 'Թ', 9: 'Ժ', 10: 'Ի', 11: 'Լ', 12: 'Խ', 13: 'Ծ', 14: 'Կ', 15: 'Հ', 16: 'Ձ', 17: 'Ղ', 18: 'Ճ', 19: 'Մ', 20: 'Յ', 21: 'Ն', 22: 'Շ', 23: 'Ո', 24: 'Չ', 25: 'Պ', 26: 'Ջ', 27: 'Ռ', 28: 'Ս', 29: 'Վ', 30: 'Տ', 31: 'Ր', 32: 'Ց', 33: 'Փ', 34: 'Ք', 35: 'Ֆ'}
font_size=36
unicode_font = ImageFont.truetype("/NEW/NotoSansArmenian-VariableFont_wdth,wght.ttf", font_size)
img = cv2.putText(image_hand, f"{dict_letter[pred]}", (x_square, y_square - 5), cv2.QT_FONT_NORMAL, 0.6, (0,0,0), 2)
Updated code:
image = np.zeros((100, 950, 3), dtype=np.uint8)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
pil_image = Image.fromarray(image)
#using mac
font = ImageFont.truetype("/System/Library/Fonts/Supplemental/Arial.ttf", 35)
draw = ImageDraw.Draw(pil_image)
draw.text((30, 30), dict_letter[pred], font=font)
image = np.asarray(pil_image)
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
cv2.imshow('image', image)
cv2.waitKey()
img =
and see what happen? – Mignonnecv2.putText(image_hand, f"{dict_letter[pred]}",(x_square, y_square - 5), unicode_font, (0,0,0), 2)
? – Mignonne> - Argument 'fontFace' is required to be an integer
– Baillieu