How can I put a degree symbol (º) on an OpenCv Video?

孤街浪徒 提交于 2021-02-20 04:07:49

问题


I made a program which make a HUD over a video, getting info from sensors and plotting the results on the video frames, refreshing every frame, and for representing degrees (inclination) I need to plot a degree symbol, but what I get it's 2 symbols ("??") in the video show. I search through this site and others too. I can't do it!!!! please, I don't know what to do, it's just that little thing that I can't do it.

This is the beginning of my program:

import cv2
from random import *
import numpy as np
from PIL import Image

capture = cv2.VideoCapture(r"e:\Usuario\Desktop\HUD\Videos\Car.mp4")
out = cv2.VideoWriter('HUD.avi',cv2.VideoWriter_fourcc('M','P','4','2'), 25, (1280, 720))

and this is the line that i need put the symbol

cv2.putText(frame, (str(data[3]) + "º"), (275,690),font,0.7,(255,255,255),1)

data it's a variable who save the values from a function, everything works perfectly, it just that symbol!!!! y try many things and no one can help me.

in this lines show the video just for check, also my program write it in a directory...

out.write(frame)
cv2.imshow("Testing", frame)

I got python 3.5.3 and windows 10 if that information it's useful for you. And i repeat, it's not the program, it just the way that i'm trying to plot the degree symbol, thats the only problem here, thanks!!!


回答1:


Try this out. But you need to install pillow pip install pillow.

import cv2
from PIL import ImageFont, ImageDraw, Image
import numpy as np

img = np.zeros((200,400,3),np.uint8)
b,g,r,a = 0,255,0,0

fontpath = "./simsun.ttc" # the font that has this "º" symbol
font = ImageFont.truetype(fontpath, 32)
img_pil = Image.fromarray(img)
draw = ImageDraw.Draw(img_pil)

draw.text((50, 80),  "100 º", font = font, fill = (b, g, r, a))

img = np.array(img_pil)

cv2.imshow("img", img)    

cv2.waitKey()
cv2.destroyAllWindows() 



来源:https://stackoverflow.com/questions/53967074/how-can-i-put-a-degree-symbol-%c2%ba-on-an-opencv-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!