Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example Python file and README Update #90

Open
wants to merge 4 commits into
base: develop-0.7.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,39 @@ Help on package tellopy:
```

## Examples

You can find basic usage of this package in example code in the examples folder.

### Mplayer
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 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`

#### Mac
`$ brew install mplayer`

### simple_takeoff
This example let Tello take off. Tello will land automatically after a few seconds.

```
$ 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.
```
Expand Down
21 changes: 13 additions & 8 deletions tellopy/examples/keyboard_and_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"""

import time
import sys
import tellopy
import pygame
import pygame.display
Expand All @@ -29,9 +28,7 @@
import os
import datetime
from subprocess import Popen, PIPE
# from tellopy import logger

# log = tellopy.logger.Logger('TelloUI')

prev_flight_data = None
video_player = None
Expand All @@ -40,6 +37,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
Expand All @@ -54,8 +58,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',
Expand Down Expand Up @@ -206,9 +211,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)
Expand Down