Wednesday, March 16, 2022

[SOLVED] Installing OpenCV in Tinker Board

Issue

I have downloaded 20170817-tinker-board-linaro-stretch-alip-v2.0.1.img for Tinker Board. I am trying to install OpenCV 3.0.0. I have followed the instructions given here : href="http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/" rel="nofollow noreferrer">http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/.

I was not able to install libjasper-dev. Hence, instead of libpng12-dev, I have installed libpng.

I am trying to compile OpenCV on Tinker Board since yesterday morning. But have been getting following errors during building process:

/usr/include/c++/6/cmath:106:11: error: ::acos has not been declared

Followed by all the math formula triggers similar errors.

Which Debian version is stable for OpenCV? Should I install a lower version of OpenCV? Can someone help?


Solution

I successfully managed to install OpenCV on a TinkerBoard. The following were the steps:

  1. Format a 16 GB memory card to FAT32
  2. Download debian image 20170817-tinker-board-linaro-stretch-alip-v2.0.1.img for tinker board from here.

  3. Copy the img file on to the memory card

sudo dd if=/path/to/your/imgfile of=/path/to/your/memorycard bs=4M

a lot of help on this is already available in SO.

  1. Before powering on ensure that you connect your tinker board to the internet through a lan cable.

  2. Once powered on reset the system time with sudo dpkg-reconfigure tzdata. Debian image for tinker board already has ntp installed. Wait a couple of minutes for the tinker board to adjust the board time from the network.

  3. To install opencv and its dependant library, I have taken the instructions given here ....though I had to make some custom library installations but it was very helpful. Please note, my purpose of using Opencv on Tinker Board is to process live video's and hence my focus was more towards installing appropriate video codecs.

The following were the steps:

sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
sudo apt-get -y autoremove

You may face the following warning messages during installation of perl applications:

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = "en_US.utf8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Though this doesn't impact your installation of OpenCV, after spending 3 days in trying to compile Opencv on tinker board I do not want to leave anything for a chance.

Use the following to suppress these warning messages:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
dpkg-reconfigure locales

Thanks to this post.

# INSTALL THE DEPENDENCIES

# Build tools:
sudo apt-get install -y build-essential cmake

# GUI (if you want to use GTK instead of Qt, replace 'qt5-default' with 'libgtkglext1-dev' and remove '-DWITH_QT=ON' option in CMake):  I just went with qt5 itself.

sudo apt-get install -y qt5-default libvtk6-dev

# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libopenexr-dev libgdal-dev

Pls note libjasper-dev is unavailable for this version of Debian and hence I have removed from the above Media I/O list.

# Video I/O:
sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev

sudo apt-get install -y gstreamer1.0-plugins-*
sudo apt-get install libxine-dev

# Parallelism and linear algebra libraries:
sudo apt-get install -y libtbb-dev libeigen3-dev

# Python:
sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy

sudo apt-get install python-pip

# Java:
sudo apt-get install -y ant default-jdk

# Documentation:
sudo apt-get install -y doxygen

Get OpenCV. I decided to go with version 3.0.0 as my development was in this version. You may choose a different version.

sudo apt-get install -y unzip wget
wget https://github.com/opencv/opencv/archive/3.0.0.zip
unzip 3.0.0.zip
rm 3.0.0.zip

Build OpenCV.

mv opencv-3.0.0 OpenCV
cd OpenCV
mkdir build
cd build

cmake -DWITH_QT=ON -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_FFMPEG=0 -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF ..

A change here from the original script - is the addition of -DWITH_FFMPEG=0, as FFMPEG library was missing and I was not in a frame of mind to install the same. You may want to do so.

make

Though TinkerBoard supports make -j4 i chose to go slow with make. The compile with make took almost 2.5 hours with lot of seemingly indentation errors in c++ codes but finally the compile gets over.

sudo make install
sudo ldconfig

$ python
>>> import cv2
>>> cv2.__version__
'3.0.0'


Answered By - Apricot
Answer Checked By - Pedro (WPSolving Volunteer)