Introduction: Object Detection W/ Dragonboard 410c or 820c Using OpenCV and Tensorflow.

About: Just a guy.

This instructables describes how to install OpenCV, Tensorflow, and machine learning frameworks for Python 3.5 to run the Object Detection application.

Step 1: Requirements

You will need the following itens:

    Download the file (In the end of this step), unzip and copy to the MicroSD card;
    Obs: If using an DB820c, download the file, unzip and move to /home/*USER*/ to ease the use of the commands.

    • A USB Hub;
    • A USB camera (Linux compatible);
    • A USB mouse and keyboard;
    • An internet connection.

    Obs: Follow this instructables in the DragonBoard browser if possible, facilitating the copying of the commands.

    Step 2: Mounting the MicroSD Card (only W/ DB410c)

    • 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 (e.g. mmcblk1p1)
    $ 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
    • Go to the Object Detector scripts folder:
    $ cd object_detector_tensorflow_opencv/scripts/
    • Run the environment setup script:
    $ sudo bash
    • Update the system:
    $ sudo apt update
    • Install these packages:
    $ sudo apt install -y protobuf-compiler gcc-aarch64-linux-gnu
    g++-aarch64-linux-gnu debootstrap schroot git curl pkg-config zip
    unzip python python-pip g++ zlib1g-dev default-jre 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 ffmpeg python-opengl
    • Go to this directory:
    $ cd /usr/src
    • Download Python 3.5:
    $ sudo wget <a href="" rel="nofollow"></a>
    • 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
    • Download Tensorflow 1.11 whl:

    $ wget <a href="" rel="nofollow"></a>
    • Install tensorflow:
    $ sudo python3.5 -m pip install tensorflow-1.11.0-cp35-none-linux_aarch64.whl
    • Clone OpenCV and OpenCV Contrib repositories:
    $ sudo git clone -b 3.4 && sudo git clone -b 3.4  
    • Go to directory:
    $ cd opencv
    • Create build directory and go to it:
    $ sudo mkdir build && cd build
    • Run CMake:
    • Compile OpenCV with 4 cores:
    $ sudo make -j 4
    • Install OpenCV :
    $ sudo make install
    • Go to the chosen directory:
    (820c) $ cd ~
    (410c) $ cd ~/sdfolder
    • Go to scripts directory:
    $ cd object_detector_tensorflow_opencv/scripts/
    • Install Python3.5 requirements:
    $ sudo python3.5 -m pip install -r requirements.txt --no-cache-dir
    • Test imports:
    $ python3.5
    >> import cv2
    >> import tensorflow 

    Obs: If cv2 returns import error, run make install in OpenCV build folder and try again.

    • Go to the chosen directory:
    (820c) $ cd ~
    (410c) $ cd ~/sdfolder 
    • Download cocoapi repository:
    $ git clone <a href="" rel="nofollow"></a>
    • Download Tensorflow models repository:
    $ git clone <a href="" rel="nofollow"></a>
    • Go to this directory:
    $ cd cocoapi/PythonAPI
    • Edit the file Makefile, changing python to python3.5 in line 3 and 8 then save the file (using nano as an example):
    $ nano Makefile
    • Compile the cocoapi:
    $ sudo make

    Obs: If ‘make’ command doesn’t compile, try reinstalling cython with:

    $ sudo python3.5 -m pip install cython
    • Copy pycocotools to tensorflow /models/research directory:
    (820c) $ cp -r pycocotools ~/models/research/ 
    (410c) $ cp -r pycocotools ~/sdfolder/models/research/
    • Go to the chosen directory:
    (820c) $ cd ~ 
    (410c) $ cd ~/sdfolder
    • Go to models/research directory:
    $ cd models/research
    • Compile with protoc:
    $ protoc object_detection/protos/*.proto --python_out=.
    • Export environment variable:
    $ export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
    • Test the environment:
    $ python3.5 object_detection/builders/

    Obs: It must return OK, otherwise the aplication won't work. If don't, carefully search for any mistake in the process of installing the required frameworks.

    Step 4: Running the Object Detection API

    With all frameworks configured, it’s now possible to run the object detection API that uses OpenCV along with Tensorflow.

    • Go to the chosen directory:
    (820c) $ cd ~
    (410c) $ cd ~/sdfolder
    • Go to object detection directory:
    $ cd object_detector_tensorflow_opencv/
    • Now run the application:
    $ python3.5

    Now the Dragonboard will stream the video through the network. To see the output video open the browser in the DB and go to "".