From 1e571b55c28a06f46bb4709ee2c490b3a521fc80 Mon Sep 17 00:00:00 2001 From: Walter Date: Mon, 26 Oct 2020 11:34:33 -0400 Subject: [PATCH 1/4] feat: made keyboard_and_video.py platform neutral A function was added to keyboard_and_video.py (get_file_path), that creates a file path based on the OS you're running on. Recording and image taking was updated to use these functions. --- tellopy/examples/keyboard_and_video.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tellopy/examples/keyboard_and_video.py b/tellopy/examples/keyboard_and_video.py index 7e12f5e3..41c316bf 100755 --- a/tellopy/examples/keyboard_and_video.py +++ b/tellopy/examples/keyboard_and_video.py @@ -19,7 +19,6 @@ """ import time -import sys import tellopy import pygame import pygame.display @@ -29,9 +28,8 @@ import os import datetime from subprocess import Popen, PIPE -# from tellopy import logger +from platform import system -# log = tellopy.logger.Logger('TelloUI') prev_flight_data = None video_player = None @@ -40,6 +38,13 @@ wid = None date_fmt = '%Y-%m-%d_%H%M%S' + +def get_file_path(file): + if system() == 'Windows': + return os.path.join(os.environ['USERPROFILE'] + "\\Pictures", file) + else: + return os.path.join(os.environ['HOME'] + "/Pictures", file) + def toggle_recording(drone, speed): global video_recorder global date_fmt @@ -54,8 +59,9 @@ def toggle_recording(drone, speed): return # start a new recording - filename = '%s/Pictures/tello-%s.mp4' % (os.getenv('HOME'), - datetime.datetime.now().strftime(date_fmt)) + filename = 'tello-{}.mp4'.format (datetime.datetime.now().strftime(date_fmt)) + filename = get_file_path(filename) + video_recorder = Popen([ 'mencoder', '-', '-vc', 'x264', '-fps', '30', '-ovc', 'copy', '-of', 'lavf', '-lavfopts', 'format=mp4', @@ -206,9 +212,9 @@ def videoFrameHandler(event, sender, data): def handleFileReceived(event, sender, data): global date_fmt # Create a file in ~/Pictures/ to receive image data from the drone. - path = '%s/Pictures/tello-%s.jpeg' % ( - os.getenv('HOME'), - datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S')) + file = 'tello-{}.jpeg'.format(datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S')) + + path = get_file_path(file) with open(path, 'wb') as fd: fd.write(data) status_print('Saved photo to %s' % path) From e52a2e586b111150a1497c704b5e6708781921e8 Mon Sep 17 00:00:00 2001 From: Walter Date: Mon, 26 Oct 2020 11:54:26 -0400 Subject: [PATCH 2/4] feat: added an mplayer section and additional example Instruction for installing mplayer in 3 major environments was added, along with placing an example for using video_and_keyboard.py. --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3817b740..2ba59667 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,22 @@ Help on package tellopy: ``` ## Examples - You can find basic usage of this package in example code in the examples folder. +### Mplayer +The examples assume that you have mplayer installed and configured in your path. + +#### Windows +Download Mplayer for Windows from [SourceForge](https://sourceforge.net/projects/mplayerwin/files/MPlayer-MEncoder/r38151/mplayer-svn-38151-x86_64.7z/download). + +Unzip the file via [7zip](https://www.7-zip.org/), and the extracted folder to your PATH (see [here for env help](https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/)). + +#### Linux +`$ sudo apt install mplayer mplayer-gui` + +#### Mac +`$ brew install mplayer` + ### simple_takeoff This example let Tello take off. Tello will land automatically after a few seconds. @@ -41,6 +54,16 @@ This example let Tello take off. Tello will land automatically after a few secon $ python -m tellopy.examples.simple_takeoff ``` +### keyboard_and_video +Display the realtime video stream from Tello. +``` +$ pip install av +$ pip install opencv-python +$ pip install image +$ pip install pygame +$ python -m tellopy.examples.keyboard_and_video +``` + ### video_effect Filter and display the realtime video stream from Tello. ``` From f9c026e6dd8b71be802da27a57bae7045144e20a Mon Sep 17 00:00:00 2001 From: Walter Date: Mon, 26 Oct 2020 12:14:22 -0400 Subject: [PATCH 3/4] refactor: removed unnecessary import --- tellopy/examples/keyboard_and_video.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tellopy/examples/keyboard_and_video.py b/tellopy/examples/keyboard_and_video.py index 41c316bf..20124a9f 100755 --- a/tellopy/examples/keyboard_and_video.py +++ b/tellopy/examples/keyboard_and_video.py @@ -28,7 +28,6 @@ import os import datetime from subprocess import Popen, PIPE -from platform import system prev_flight_data = None From 112fec56854a3ac3ede813b3d99de20e4e0bc95f Mon Sep 17 00:00:00 2001 From: Walter Date: Mon, 26 Oct 2020 12:15:18 -0400 Subject: [PATCH 4/4] fix: grammar problems --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ba59667..dcc5d263 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,12 @@ Help on package tellopy: You can find basic usage of this package in example code in the examples folder. ### Mplayer -The examples assume that you have mplayer installed and configured in your path. +The video examples assume that you have mplayer installed and configured in your path. #### Windows Download Mplayer for Windows from [SourceForge](https://sourceforge.net/projects/mplayerwin/files/MPlayer-MEncoder/r38151/mplayer-svn-38151-x86_64.7z/download). -Unzip the file via [7zip](https://www.7-zip.org/), and the extracted folder to your PATH (see [here for env help](https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/)). +Unzip the file via [7zip](https://www.7-zip.org/), and add the extracted folder to your PATH (see [here for env help](https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/)). #### Linux `$ sudo apt install mplayer mplayer-gui`