Skip to content

Instantly share code, notes, and snippets.

@nmaggioni
Last active March 1, 2020 13:17
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 nmaggioni/e42d3f4eb242808df751b13413ebf22c to your computer and use it in GitHub Desktop.
Save nmaggioni/e42d3f4eb242808df751b13413ebf22c to your computer and use it in GitHub Desktop.
A simple pitch/roll/yaw rates calculator based on DVR frames count, useful for when you cannot record blackbox logs.
#! /usr/bin/env python
"""
A simple pitch/roll/yaw rates calculator based on DVR frames count, useful for when you cannot record blackbox logs.
Usage: record a DVR of your aircraft doing a few flips/rolls in each axis, and then count how many frames it took to execute the maneuver and turn back level/straight.
"""
from math import ceil
from os.path import isfile
from statistics import mean
try:
from pymediainfo import MediaInfo
except ImportError:
try:
import cv2
except ImportError:
pass
"""
Calculate a maneuver's durations based on how many video frames it took to complete.
"""
def calc_time(avg_frames_count, video_fps):
return avg_frames_count / video_fps
"""
Convert a maneuver's duration in degrees per seconds, rounding up to the nearest ten (ex.: 467 -> 470).
"""
def calc_dps_round_to_10th(maneuver_time):
return ceil((360 / maneuver_time) / 10.0) * 10
"""
Get the path of the DVR recording.
"""
def get_dvr_path():
dvr_path = ""
while dvr_path == "" or not isfile(dvr_path):
dvr_path = input("Specify DVR file path: ")
return dvr_path
"""
Extract the FPS value from the DVR recording.
This will be done automatically if the needed dependencies are found, else the user will have to enter this value manually.
"""
def get_dvr_fps():
try:
if MediaInfo:
media_info = MediaInfo.parse(get_dvr_path())
for track in media_info.tracks:
if track.track_type == 'Video':
return float(track.frame_rate)
except NameError:
pass
try:
if cv2:
return cv2.VideoCapture(get_dvr_path()).get(cv2.CAP_PROP_FPS)
except NameError:
pass
print("*** Pymediainfo or OpenCV not found, DVR's FPS will need to be specified manually.")
return float(input("Specify DVR's FPS: "))
if __name__ == '__main__':
fps = get_dvr_fps()
print("DVR's FPS: {}".format(round(fps, 3)))
frames = input("\nSpecify the number of frames needed to roll/flip in the desired axis (multiple data points separated by a comma): ").split(',')
frames = list(map(float, frames))
avg_frames = mean(frames)
maneuver_time = calc_time(avg_frames, fps)
maneuver_dps = calc_dps_round_to_10th(maneuver_time)
print("\nIt takes {}s to roll/flip in this axis, corresponding to a rate of about {}°/s.".format(round(maneuver_time, 2), maneuver_dps))
numpy==1.18.1
opencv-python-headless==4.2.0.32
pymediainfo==4.1
Specify DVR file path: /tmp/PICT0038.AVI
DVR's FPS: 25.057
Specify the number of frames needed to roll/flip in the desired axis (multiple data points separated by a comma): 18,19,18,17,24
It takes 0.77s to roll/flip in this axis, corresponding to a rate of about 470°/s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment