Introduction: Augmented Reality (AR) for Dragonboard410c or Dragonboard820c Using OpenCV and Python 3.5

About: Luiz Eduardo Teixeira. Graduado em engenharia de computação pelo Inatel, pretende fazer a diferença na área da tecnologia. Apaixonado por sistemas embarcados, microcontroladores, IoT e aprender novas tecnologi…

This instructables describes how to install OpenCV, Python 3.5, and dependencies for Python 3.5 to run the augmented reality application.

Step 1: Requirements

You will need the following itens:

  • A Dragonboard 410c or 820c;
  • A clean installation of Linaro-alip/developer;
  • DB410c: Tested in version v431.link

https://snapshots.linaro.org/96boards/dragonboard4..

  • DB820c: Tested in version v228.link

https://snapshots.linaro.org/96boards/dragonboard8..

  • At least 16GB capacity MicroSD Card (If using Dragonboard 410c);
  • Download the file (in the end of this step), unzip and copy to the MicroSD card;
  • Obs: If using an Dragonboard 820c, download the file, unzip and move to /home/*USER*/ to ease the use of the commands;
  • An USB Hub;

  • An USB mouse and keyboard;

  • An internet connection.

Step 2: Mounting the MicroSD Card (Only W/ Dragonboard410c)

  • Open the terminal in the Dragonboard;
  • In the terminal run fdisk:

$ sudo fdisk -l
  • Insert the MicroSD card into the DragonBoard MicroSD card slot;

  • Run fdisk again, looking for the name (and partition) of the new device in the list:

$ sudo fdisk -l
  • Go to the root directory:

$ cd ~
  • Create a folder:

$ mkdir sdfolder
  • Mount the MicroSD card:

mount /dev/sd_card_partition_name sdfolder

Step 3: Installing Required Frameworks

  • Open the terminal in the Dragonboard;
  • In the terminal, go to a chosen directory (using "~" for the 820c and the mounted SDCard for the 410c):
(820c) $ cd 
(410c) $ cd ~/sdfolder
  • Run zram.sh script:
$ sudo bash augmented_reality/scripts/zram.sh
  • Update system:
sudo apt update && sudo apt upgrade
  • Install these packages:
sudo apt install -y debootstrap schroot git curl pkg-config zip unzip python python-pip g++ zlib1g-dev openjdk-8-jdk libhdf5-dev libatlas-base-dev gfortran v4l-utils hdf5* libhdf5* libpng-dev build-essential cmake libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libjpeg-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk2.0-dev libgtk-3-dev
  • Go to this directory:
$ cd /usr/src
  • Download Python 3.5:
sudo wget https://www.python.org/ftp/python/3.5.6/Python-3....
  • Extract the package:
$ sudo tar xzf Python-3.5.6.tgz
  • Delete the compressed package:
$ sudo rm Python-3.5.6.tgz
  • Go to the Python 3.5 directory:
$ cd Python-3.5.6
  • Enable optimizations for the Python 3.5 compilation:
$ sudo ./configure --enable-optimizations
  • Compile Python 3.5:
$ sudo make altinstall
  • Upgrade pip and setup tools:
$ sudo python3.5 -m pip install --upgrade pip && python3.5 -m pip install --upgrade setuptools
  • Install numpy:
$ python3.5 -m pip install numpy
  • Go to the chosen directory:
(820c) $ cd ~
(410c) $ cd ~/sdfolder
  • Clone OpenCV and OpenCV Contrib repositories:

$ sudo git clone -b 3.4 https://github.com/opencv/opencv.git && sudo git clone -b 3.4 https://github.com/opencv/opencv_contrib.git

  • Go to directory:
$ cd opencv
  • Create build directory and go to it:
$ sudo mkdir build && cd build
  • Run CMake:
$ sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_java=OFF -D BUILD_opencv_python=OFF -D BUILD_opencv_python3=ON -D PYTHON3_DEFAULT_EXECUTABLE=$(which python3.5) -D PYTHON3_EXECUTABLE:FILEPATH=$(which python3.5) -D PYTHON_INCLUDE_DIR=/usr/local/include/python3.5m/ -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON3_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D WITH_CUDA=OFF -D BUILD_TESTS=OFF -D WITH_TBB=ON -DBUILD_TBB=ON -D OPENCV_ENABLE_NONFREE=ON -DBUILD_opencv_xfeatures2d=OFF -D OPENGL=ON -D OPENMP=ON -D ENABLE_NEON=ON -D BUILD_PERF_TESTS= OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
  • Compile OpenCV with 4 cores:

$ sudo make -j 4
  • Install OpenCV:

$ sudo make install
  • Go to the chosen directory:

(820c) $ cd ~
(410c) $ cd ~/sdfolder
  • Install Python3.5 requirements:

$ sudo python3.5 -m pip install -r requirements.txt --no-cache-dir
  • Test imports:
python3.5
>> import cv2
>> import flask

Step 4: Running AR Application

  • Go to the chosen directory:
(820c) $ cd
(410c) $ cd ~/sdfolder
  • Go to augmented reality directory:
$ cd augmented_reality/
  • Run the application:

$ python3.5 app.py
  • Obs: Now connect the USB camera and open using a browser with the board IP address and the port (e.g. 192.168.1.1:5000), print the model saved in reference folder and place in front of webcam such as the image in the top. It's possible to change the animal by oppening the source code, going to line 92 and change the name before video capture command, the avaliable animals are: cow, fox, pirate-ship-fat, rat and wolf. It's also possible to change the reference image by changing the image inside the reference folder.