Skip to content

Instantly share code, notes, and snippets.

@7kry
Created November 6, 2020 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7kry/9188150bd4355907c9f261170e12cc41 to your computer and use it in GitHub Desktop.
Save 7kry/9188150bd4355907c9f261170e12cc41 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
# In[61]:
import PIL.Image as Image
import PIL.ImageDraw as Draw
import PIL.ImageFont as Font
import json
import os.path
import numpy
import cv2
# In[69]:
size = (1080, 190)
def generate_textimage(kph, alt):
im = Image.new('RGB', size, (0, 0, 255))
draw = Draw.Draw(im)
font = Font.truetype('/System/Library/Fonts/Menlo.ttc', 100)
text = ' Speed {:>4} km/h\nAltitude {:>4} m'.format(int(kph * 10) / 10, int(alt))
txW, txH = draw.textsize(text, font = font)
draw.text((im.width - txW, im.height - txH), text, fill = (255, 255, 255), font = font)
return cv2.cvtColor(numpy.array(im, dtype=numpy.uint8), cv2.COLOR_RGB2BGR)
# In[73]:
def json2video(path2json, path2video, fps = 60):
d = json.load(open(path2json))
out = cv2.VideoWriter(path2video, cv2.VideoWriter_fourcc(*'MP4V'), fps, size)
for i, sample in enumerate(d['1']['streams']['GPS5']['samples']):
im = generate_textimage(sample['value'][4] * 3.6, sample['value'][2])
out.write(im)
out.release()
json2video('GX030067_1_GPS5.json', 'GX030067_GPS.mp4')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment