如何在OpenCv视频中添加学位符号(º)?

2024-06-26 14:32:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了一个程序,在视频上制作一个HUD,从传感器获取信息并在视频帧上绘制结果,刷新每一帧,为了表示角度(倾斜度),我需要绘制一个度数符号,但我得到的是2个符号(“??”)在视频节目中。我搜索了这个网站和其他网站。我做不到!!!!拜托,我不知道该怎么办,只是那件小事我做不到。在

这是我课程的开始:

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

这是我需要放符号的线

^{pr2}$

数据它是一个变量,它保存函数中的值,一切都很完美,它只是那个符号!!!!你尝试了很多事情,但没有人能帮我。在

在这行显示的视频只是为了检查,我的程序写在一个目录。。。在

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

我得到了python3.5.3和windows10,如果这些信息对你有用的话。我重复一遍,这不是程序,这只是我试图绘制学位符号的方式,这是这里唯一的问题,谢谢!!!在


Tags: fromimport程序视频网站绘制符号传感器
1条回答
网友
1楼 · 发布于 2024-06-26 14:32:21

试试这个。但是你需要安装枕头。在

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

enter image description here

相关问题 更多 >