如何在OpenCv视频上放置度数符号(º)? [英] How can I put a degree symbol (º) on an OpenCv Video?

查看:133
本文介绍了如何在OpenCv视频上放置度数符号(º)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个程序,可以对视频进行HUD处理,从传感器获取信息并在视频帧上绘制结果,刷新每一帧,并表示角度(倾斜度),我需要绘制一个角度符号,但是我在视频节目中获得2个符号("??").我也通过这个网站和其他网站进行搜索.我做不到!拜托,我不知道该怎么办,那只是我不能做的那件事.

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.

这是我程序的开始:

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)

数据是一个变量,它保存函数中的值,一切正常,只是那个符号!!!y尝试很多事情,没有人可以帮助我.

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)

我得到了python 3.5.3和Windows 10(如果该信息对您有用).我再说一遍,这不是程序,而是我试图绘制度数符号的方式,这是这里唯一的问题,谢谢!!!

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!!!

推荐答案

尝试一下.但是您需要安装枕头 pip安装枕头.

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() 

这篇关于如何在OpenCv视频上放置度数符号(º)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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