Skip to content

Instantly share code, notes, and snippets.

@numpad0
Last active March 7, 2023 20:46
Show Gist options
  • Save numpad0/0840d808878d8432d9d3325ca332ca8a to your computer and use it in GitHub Desktop.
Save numpad0/0840d808878d8432d9d3325ca332ca8a to your computer and use it in GitHub Desktop.
#!/bin/python3
import os
import subprocess
# #!/bin/bash
# ffmpeg -y -i input_video_file.mp4 -an -ss 00:59:59 -t 00:10:00 -vcodec copy int1.mp4
# ffmpeg -y -i int1.mp4 -an -filter:v "crop=1920:75:0:20" -r 6 int2.mp4
# ffmpeg -y -i int2.mp4 -f lavfi -i color=cccccc:s=1920x75 -f lavfi -i color=black:s=1920x75 -f lavfi -i color=white:s=1920x75 -lavfi threshold int3.mp4
# mkdir -p ~/h3_telemetry/{alt,vel,time,joined}
# ffmpeg -i int3.mp4 -y -an -filter:v "crop=1200:75:0:0" -r 6 -q:v 1 -f image2 joined/%5d.png &
# ffmpeg -i int3.mp4 -y -an -filter:v "crop=150:75:200:0" -r 6 -q:v 1 -f image2 vel/%5d.png &
# ffmpeg -i int3.mp4 -y -an -filter:v "crop=150:75:570:0" -r 6 -q:v 1 -f image2 alt/%5d.png &
# ffmpeg -i int3.mp4 -y -an -filter:v "crop=350:75:785:0" -r 6 -q:v 1 -f image2 time/%5d.png &
# The above parameters may work or may not work, stock Tesseract models may or may not work, that is to say, nothing worked for me
# //ffmpeg -i int3.mp4 -y -an -filter:v "crop=150:75:200:0,scale=150x75,boxblur=4,eq=contrast=3,scale=300x150" -r 6 -q:v 1 -f image2 vel/%5d.png &
# //ffmpeg -i int3.mp4 -y -an -filter:v "crop=150:75:570:0,scale=150x75,boxblur=4,eq=contrast=3,scale=300x150" -r 6 -q:v 1 -f image2 alt/%5d.png &
# //ffmpeg -i int3.mp4 -y -an -filter:v "crop=350:75:785:0,boxblur=1,eq=contrast=4" -r 6 -q:v 1 -f image2 time/%5d.png &
# sudo apt -y install tesseract-ocr tesseract-ocr-eng
def run_ocr(img_nr):
img_nr = "{:05d}".format(img_nr)
time = subprocess.run("tesseract time/" + str(img_nr) + '.png stdout -l eng --psm 6 -c tessedit_char_whitelist=0123456789X-+:. 2>/dev/null', shell=True, stdout=subprocess.PIPE, text=True).stdout.strip()
vel = subprocess.run("tesseract vel/" + str(img_nr) + '.png stdout -l eng --psm 6 -c tessedit_char_whitelist=0123456789X-+:. 2>/dev/null', shell=True, stdout=subprocess.PIPE, text=True).stdout.strip()
alt = subprocess.run("tesseract alt/" + str(img_nr) + '.png stdout -l eng --psm 6 -c tessedit_char_whitelist=0123456789X-+:. 2>/dev/null', shell=True, stdout=subprocess.PIPE, text=True).stdout.strip()
csv_str = (img_nr + ',' + time + ',' + vel + ',' + alt)
return(csv_str)
with open('outfile.csv', 'w+') as file:
file.write('img_nr, time, velocity, altitude\r\n')
for i in range(1, 3598):
line = run_ocr(i)
file.write(line + '\r\n')
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment