Environment construction of "Tello_Video" on Ubuntu

Introduction

This page is

Move the Tello-Python sample "Tello_Video"

This is a supplementary page of.

Overview

Of the DJI official Python sample program "Tello-Python" for Tello  Tello_Video In order to try

--Installation of various dependent libraries --Building H.264 video decoding library

You need to do.

As an installation method, git's Tello-Python page

・ Linux(Ubuntu 14.04 and above)

 Go to the "install\Linux" folder in command line, run

 chmod +x linux_install.sh
 ./linux_install.sh

is what it reads. That is,

Move folders, change file attributes, execute shell files


$ cd install/Linux/
$ chmod +x linux_install.sh
$ ./linux_install.sh

And type the command. ** linux_install.sh ** </ font> is a shell script that automatically builds the environment for Linux.

If you are familiar with Linux, you may think, "Why, if you have an sh file, you can run it." However, if you execute it as it is

<! --- Since the upgrade of pip itself is done without permission, pip problems may occur depending on the distribution->

--OpenCV version 3.x series is not installed

<! ---- Is cmake installed with apt or pip->

Will occur.

・ As of Ubuntu 16.04 (September 2019), If you don't specify the version with sudo pip install opencv-python, 4.1.1.26 will be included. If you use sudo apt install python-opencv, 2.4.9.1 will be included.

・ As of Ubuntu 18.04 (September 2019), If you don't specify the version with sudo pip install opencv-python, 4.1.1.26 will be included. With sudo apt install python-opencv, 3.2.0 is included, so there is no problem, but pip is used in the shell file.

So, you can solve the problem by rewriting ** linux_install.sh. ** **

Prerequisites

We will assume that Tello-Python is installed in your home folder (~).

Move directory

First, open the console (terminal) and type the following command to move to the Tello-Video folder.

cd(change_directory)


$ cd ~/Tello-Python/Tello-Video

Looking inside Tello_Video with the ls command,

Tello_Contents of Video


$ ls
LICENSE.md  README.md  h264decoder  img  install  main.py  tello.py  tello_control_ui.py

You can see that there is a directory called ʻinstall`. The contents of this directory are

In the install directory


$ ls install/
Linux  Mac  Windows

It looks like this, and the installation files are placed in each directory of Linux, Mac, and Windows, but ** none of them are old and useless </ font> * *.

However, Linux can be accommodated with a few changes.

Linux update

First, update Linux to the latest state.

Update to the latest status


$ sudo apt update
$ sudo apt upgrade -y

Rewriting linux_install.sh

For Ubuntu, you can install it automatically by slightly rewriting the contents of ** linux_install.sh ** </ font>.

That is, the 30th line sudo pip install opencv-python To sudo pip install opencv-python==3.4.5.20 Just rewrite as. 3.4.5.20 is the latest version of 3.x series that can be installed with pip (as of September 2019)

Rewrite linux_install.sh using a text editor (vi, nano, gedit, pluma, mousepad, etc.). Below is an example of rewriting with nano.

Example of rewriting with nano


$ nano install/Linux/linux_install.sh

When editing with nano, save the file with ctrl + o and exit the editor with ctrl + x.

linux_install.sh


#!/bin/sh

echo 'Compiling and Installing the Tello Video Stream module'
echo 'You might need to enter your password'

cd .. 
cd ..
sudo apt-get update -y

# install python 2.7
sudo apt-get install python2.7 python-pip -y
sudo pip install --upgrade pip

#switch to python2.7
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 150 
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100

sudo apt-get update -y

# install cmake
#sudo apt-get install cmake -y
sudo pip install cmake

# install dependencies
sudo apt-get install libboost-all-dev -y
sudo apt-get install libavcodec-dev -y
sudo apt-get install libswscale-dev -y
sudo apt-get install python-numpy -y
sudo apt-get install python-matplotlib -y
sudo pip install opencv-python==3.4.5.20   #Just add here
sudo apt-get install python-imaging-tk

# pull and build h264 decoder library
cd h264decoder
mkdir build
cd build
cmake ..
make

# copy source .so file to tello.py directory
cp libh264decoder.so ../../

echo 'Compilation and Installation Done!'

Run linux_install.sh

After rewriting, move to the folder containing the shell file and Give execute permission with chmod and execute.

Move folders, change file attributes, execute shell files


$ cd ~/Tello-Python/Tello_Video/install/Linux/
$ chmod +x linux_install.sh
$ ./linux_install.sh

It will be installed automatically.

After the installation is complete, go back to the Tello-Video directory.

Go back up two levels


$ cd ../../

** This completes the work. </ font> **

important point

The points to note when installing with linux_install.sh are ** Be sure to move the current directory to ~ / Tello-Python / Tello_Video / install / Linux / Then run linux_install.sh ** </ font>.

I mean,

linux_install.Excerpt from sh


cd ..    #Move to the next higher directory
cd ..    #Move to the next higher directory
sudo apt-get update -y

(Abbreviation)

# pull and build h264 decoder library
cd h264decoder    #Enter a folder called h264 decoder
mkdir build
cd build          #Enter a folder called build
cmake ..
make

# copy source .so file to tello.py directory
cp libh264decoder.so ../../      #Copy files to a folder two levels higher

In this way, go up the folder two levels and install apt and pip. This is because we are moving to the h264decoder folder and building and copying the library.

If, from the Tello_Video directory, do the following

Don't call the file directly like this


$ ./install/Linux/linux_install.sh

What happens if you run the shell with a relative path? It goes up two levels of ~ / Tello-Python / Tello_Video /, that is, up to the home directory ~ / and tries to enter h264 decoder. Of course, it cannot be built.

in conclusion

I'd like to write how to build an environment for Linux, Raspberry Pi, Windows, and Mac, but when will all be finished? .. ..

Recommended Posts