I try to use python OpenCV (Windows 10, Python 3.6) to write title in image, when the text is English it works, but when I use Chinese title, it was out of order.
Below is my code:
import cv2
cap = cv2.VideoCapture(0) # open webcam
while True:
ret, frame = cap.read() # 读Read the camera picture
cv2.imshow('中文', frame) # reveal
if cv2.waitKey(1) & 0xFF == ord('q'): #
break
cap.release()
cv2.destroyAllWindows()
When title = "English" # just work, below is the output image:
When title = "中文" # doesn't work, below is the output image:
What I have tried adding encode('utf-8') or gbk to the title and then decoding it with errors='ignore', but it doesn't work, the title is still garbled.
I currently know that PIL can solve the problem of Chinese garbled characters in cv2.imshow's put text from How to draw Chinese text on the image using cv2.putText
correctly?, but I don't know how to solve the title problem, and i think they are different.