[PYTHON] Building an environment for "Tello_Video" on Raspbian

(Added on March 6, 2020) I tried it with Raspberry Pi 4 and Raspbian Buster with 4GB of memory. It's moving more smoothly than on Raspberry Pi 3 and Stretch.

Introduction

This page is

Move the Tello-Python sample "Tello_Video"

It 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 on 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

It means to 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, on Raspberry Pi, even if I follow the procedure, it does not work. The causes are the following two points.

--cmake cannot be installed with the default pip. Should be installed with apt --OpenCV installation is not as easy as Intel-based Ubuntu

cmake can be handled by rewriting linux_install.sh, but OpenCV is troublesome. This time, I will do it with a little omission.

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> * *.

In the case of Raspberry Pi, the problem is that installing OpenCV is not easy with apt or pip.

Raspbian update

First, let's update Linux to the latest state.

Update to the latest status


$ sudo apt update
$ sudo apt upgrade -y

First introduction of OpenCV

The mainstream of OpenCV installation of Raspberry Pi is a 2-hour course that downloads the source and builds it by yourself (crying). However, it is recommended to install using the debian package built and published by mt08 on the reference page below because it is very easy and short.

--In the case of Stretch Easy introduction of OpenCV3 / 4 to Raspberry Pi 3 --For Buster Raspberry Pi: OpenCV4 for Buster

(Of course, if you are an expert who says "I'm afraid that the pre-built Trojan horse is loaded," please build and install it yourself.)

For Raspbian Stretch

Easy introduction of OpenCV3 / 4 to Raspberry Pi 3

First, copy the series of commands written at the beginning of the above page and paste them into a text editor to create a shell file. The file name can be anything, but here it should be cv_install.sh. I will write the excerpted command below, but it is recommended to copy and paste from the head family because there may be updates.

cv_install.Let's create a file called sh


OPENCV_DEB=libopencv3_3.4.6-20190415.1_armhf.deb

curl -SL https://github.com/mt08xx/files/raw/master/opencv-rpi/${OPENCV_DEB} -o ${OPENCV_DEB}
sudo apt autoremove -y libopencv{3,4}
sudo apt install -y ./${OPENCV_DEB}

#
sudo ldconfig
python2 -c 'import cv2; print(cv2.__version__)'
python3 -c 'import cv2; print(cv2.__version__)'

Save cv_install.sh in your home directory Give execute permission and then execute.

Installation with pre-built packages


$ chmod +x cv_install.sh
$ ./cv_install.sh

The file libopencv3_3.4.6-20190415.1_armhf.deb is downloaded to your home directory, but you can delete it after installation.

As written at the end of cv_install.sh,

Checking the operation of OpenCV with Python(Version display)


python2 -c 'import cv2; print(cv2.__version__)'
python3 -c 'import cv2; print(cv2.__version__)'

It will import it in Python and try to see if it works. If OpenCV version 3.4.6 is displayed twice, it is successful. If an error occurs here, it means that there is something wrong with the environment.

For Raspbian Buster

Raspberry Pi: OpenCV4 for Buster

The above page was used as a hint for installing OpenCV3 on Buster. There is no shell source that can be copied and pasted like in Stretch, so I will make it myself.

The latest deb package file for Buster https://github.com/mt08xx/files/tree/master/opencv-rpi/raspbian-buster It's here. The package for Raspberry Pi 2, 3 and 4 contains ʻarmv7lin the file name. As of March 2020,libopencv3_3.4.9-20191223.1_armv7l.deb` was the latest.

Copy the command below and paste it into a text editor to create a shell file. The file name should be cv_install_buster.sh.

cv_install_buster.Let's create a file called sh


curl -SLO https://github.com/mt08xx/files/raw/master/opencv-rpi/raspbian-buster/libopencv3_3.4.9-20191223.1_armv7l.deb
sudo apt autoremove -y libopencv{3,4}
sudo apt install -y ./libopencv3_3.4.9-20191223.1_armv7l.deb

#
sudo ldconfig
python2 -c 'import cv2; print(cv2.__version__)'
python3 -c 'import cv2; print(cv2.__version__)'

Save cv_install_buster.sh in your home directory Give execute permission and then execute.

Installation with pre-built packages


$ chmod +x cv_install_buster.sh
$ ./cv_install_buster.sh

The file libopencv3_3.4.9-20191223.1_armv7l.deb is downloaded to your home directory, but you can delete it after installation.

If OpenCV version 3.4.9 is displayed twice, it is successful. If an error occurs here, it means that there is something wrong with the environment.

Rewriting linux_install.sh

Then rewrite linux_install.sh for Raspberry Pi.

  1. Change cmake from pip installation to apt installation
  2. Since the installation of OpenCV has already been completed, comment it out and disable it.

Perform the above two tasks.

That is, the 21st and 22nd lines

Change before


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

To

After change


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

Just rewrite to. Also, the installation of OpenCV on the 30th line

Comment on OpenCV installation


#sudo pip install opencv-python

Disable it like this.

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    #Here#Remove and enable
#sudo pip install cmake     #Comment out here

# 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   #Comment out 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. If the file download for apt or pip fails, Quit with Ctrl + c and try again. If you do it about 3 times, it should be installed safely. (-_- ;;;

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

Go back up two levels


$ cd ../../

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

in conclusion

I can install it on Raspberry Pi, but ** Decoding errors occur frequently ** ** Even if you try to terminate the Tello_Video program, it will become a zombie and will not die **. Trouble occurs frequently. It's heavy anyway.

I wonder if Raspberry Pi 4 with 4GB of memory is okay. .. .. I will also try it with 4 and Buster.

Next, I will write how to build an environment on Windows.

Recommended Posts