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: Requierments

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.

    • An USB Hub;
    • An USB camera (Linux compatible);
    • An 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:
    $ 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 set_Env.sh
    • 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 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 ffmpeg python-opengl
    • Go to this directory:
    $ cd /usr/src
    • Download Python 3.5:
    $ sudo wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
    • 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 https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.11.0/tensorflow-1.11.0-cp35-none-linux_aarch64.whl
    • 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 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<br>BUILD_OPENCV_DNN=ON -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
    • 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 https://github.com/cocodataset/cocoapi.git
    • Download Tensorflow models repository:
    $ git clone https://github.com/tensorflow/models.git
    • 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/model_builder_test.py

    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 app.py

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

    Share

      Recommendations

      • Trash to Treasure

        Trash to Treasure
      • Build a Tool Contest

        Build a Tool Contest
      • Organization Contest

        Organization Contest

      2 Discussions

      1
      None
      randofo

      5 days ago

      Thanks for sharing. Do you have a bigger project in mind for this tech?

      1 reply
      0
      None
      LuizTeixeirarandofo

      Reply 8 hours ago

      For now we just want to improve the FPS for multithreading and the model used to recognize objects , test other datasets and study its accuracy.