Opencv 3.2 Install Dependencies Error

release
96boards

#1

I have a dragonboard 410c with the latest debian linux OS. I’m attempting to install opencv 3.2.0 as described in http://www.96boards.org/blog/part-2-home-surveillance-project-96boards/ using the latest Linux based OS on the dragonboard 410c. There seems to be an issue installing the necessary dependencies of opencv

Code

$ sudo apt-get install libpng12-dev libjasper-dev

The code throws an “unable to locate package libpng12” error (does the same for libjasper-dev). I scoured through the internet and only found solutions for Ubuntu based solutions. Any suggestions on how to resolve the issue?


#2

This worked for me to get OpenCV installed and working on the latest 17.04.1 release. I based it on the how to install OpenCV from source instructions, but I made some minor changes to make it work.

# KEEP UBUNTU OR DEBIAN UP TO DATE

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

# 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):
sudo apt-get install -y qt5-default
sudo apt-get install -y libqt5opengl5-dev
sudo apt-get install -y python3-pyqt5.qtopengl python3-opengl

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

#fetch and build libjasper
mkdir jasper
cd jasper
wget http://www.ece.uvic.ca/~frodo/jasper/software/jasper-2.0.10.tar.gz
tar -vzxf jasper-2.0.10.tar.gz
cd jasper-2.0.10
mkdir BUILD
cd BUILD
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_INSTALL_RPATH=YES -DCMAKE_INSTALL_DOCDIR=/usr/share/doc/jasper-2.0.10 …
make
sudo make install
cd …/…/…

# 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 libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install -y libxvidcore-dev libx264-dev

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

# gstreamer, opengl and vtk
sudo apt-get install -y libgstreamer1.0-0
sudo apt-get install -y freeglut3-dev libglew-dev libglm-dev mesa-common-dev
sudo apt-get install -y libvtk6-qt-dev python-vtk6

# Python:
sudo apt-get install -y python3-pip
sudo apt-get install -y python3-dev python3-tk python3-numpy
sudo apt-get install -y python3-scipy python3-matplotlib
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

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

# Documentation:
sudo apt-get install -y doxygen
sudo apt-get install -y unzip wget
sudo apt-get clean

# INSTALL THE LIBRARY (YOU CAN CHANGE ‘3.2.0’ FOR THE LAST STABLE VERSION)

#wget https://github.com/opencv/opencv/archive/3.2.0.zip
#unzip 3.2.0.zip
#rm 3.2.0.zip
#mv opencv-3.2.0 OpenCV
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout master
mkdir build
cd build
cmake -DWITH_LIBV4L=ON -DWITH_QT=ON -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DWITH_OPENMP=ON -DWITH_GSTREAMER=ON -DWITH_OPENCL=ON …
make -j4
sudo make install
sudo ldconfig

#install the imutils (which depend on mtools and the OpenCV just built)
sudo apt-get install -y v4l-utils
sudo -H pip3 install setuptools --upgrade
pip3 install wheel
pip3 install imtools
pip3 install imutils

Full disclosure: I am an employee of Qualcomm Canada, any opinions I may have expressed in this or any other post may not reflect the opinions of my employer.


#3

I forgot to mention, you need enough swap space to rebuild OpenCV, I ran this script first:

echo Creating 1.5GB swapfile
sudo dd if=/dev/zero of=/swapfile count=1500 bs=1M
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo sed -i ‘$a /swapfile none swap sw 0 0\n’ /etc/fstab
sudo sed -i ‘$a export ARCH=arm64\n’ ~/.bashrc
sudo sed -i ‘$a export MONITOR_PORT=/dev/tty96B0\n’ ~/.bashrc
sudo sed -i ‘$a export JAVA_TOOL_OPTIONS="-Dgnu.io.rxtx.SerialPorts=/dev/tty96B0"\n’ ~/.bashrc
sudo sed -i ‘$a export PYTHONPATH=/usr/local/lib/python3.5/dist-packages:/usr/local/lib/python2.7/site-packages\n’ ~/.bashrc
sudo sed -i ‘$a xset -dpms; xset s off\n’ ~/.bashrc

of course once you fill the eMMC with swap space you will run out of space for OpenCV, so you will likely have to do the build on a SDCard.

Full disclosure: I am an employee of Qualcomm Canada, any opinions I may have expressed in this or any other post may not reflect the opinions of my employer.


#4

Hi @muffin_man

It’s a good idea to always copy 'n paste the error in full (including the command that caused the error) so folks here can better see what might be going wrong.

So, I can’t be sure without more detail, but I suspect that the problem arises because you have never previously run apt update to populate the package database (which noticeably, is the first line of @ljking instructions above).


#5

Just a thought… Could these instructions be made simpler (and the install quicker) if a Python Wheel was built for OpenCV?

With the announcement of the camera module yesterday it seems like everyone building from source is not a good way forward.


#6

well, the root cause is that OpenCV is not very well integrated/maintained in Debian. At least it is very much outdated in Debian. Debian Stretch which is the release we use for DB410c comes with OpenCV 2.4.9.1 (https://packages.debian.org/fr/source/stretch/opencv).

I am not sure if this version of OpenCV would satisfy any of your usages…

If someone wants to work on a Debian package backport to bring OpenCV 3.2, i can offer to upload the package into the Linaro overlay to make it widely available for all 96boards/Debian users, but i won’t spend time on doing the packaging work myself. Note that there is a 3.1 package in Debian experimental, so this might be worth looking at that… https://packages.debian.org/fr/source/experimental/opencv.

It seems that OpenEmbedded has a more up-to-date, at least there is recipe for 3.2 version there: https://layers.openembedded.org/layerindex/recipe/39865/. OE ‘morty’ release , which is the one we support the most as 3.1 though…


#7

@muffin_man You can use the updated instructions for building OpenCV on dragonboard here. The instructions on blog post is outdated for >=17.04 releases.

Hope it helps!

Thanks,
Mani


#8

Hi @mani:

I tried out general purpose instructions on a 17.04.1 system. The problem that @muffin_man ran into is the same for me:

sudo apt-get install jasper-dev

failed with the message:

E: Unable to locate package jasper-dev

This is why I added the block of instructions to install jasper from source. You went back and added all of the older Jessie packages instead.

Full disclosure, I am an employee of Qualcomm Canada, any opinions I may have expressed in this or any other post may not reflect the opinions of my employer.


#9

Hello @ljking,

You are right! The reason I added old jessie source is that, 17.04.1 contains many packages modified. One instance of such is that, they removed libjpeg. Also, python-pip is not working so I switched to easy_install.

At the end of day, my motive is to provide users an _easy_to_follow instructions :slight_smile: I’m also thinking of creating a ppa repo as it will make the life easier.

Thanks,
Mani


#10

hi @Mani,

we have PPA already for our Debian builds, see https://wiki.linaro.org/OBS. As I said in my last message, if someone creates a proper Debian source package for our Stretch overlay, i am willing to publish it into our main overlay.


#11

@ljking thank you for the response. The solution seems to working. The model is building on my SD card because I ran out of space on the board. Will update when the build finishes


#12

Do you guys know how to build the TBB for OpenCV on DragonBoard? I get build errors…


#13

Hi @Nadav_B

The instructions in this thread already install TBB (libtbb-dev), and compile OpenCV with TBB (cmake -DWITH_TBB=ON…).

I did try building TBB 2017-U8 from the GitHub source files and it compiled cleanly.

Full disclosure, I am an employee of Qualcomm Canada, any opinions I may have expressed in this or any other post may not reflect the opinions of my employer.


#14

Hi Mani,

For http://www.96boards.org/blog/part-2-home-surveillance-project-96boards/

Did you install Debian/Linux on eMMC or SD card?

I tried on eMMC and installed 8gb swapfile on SD card and It freezes on Cmake processing at 49%.

I’m new with Linux & Dragon Board 410c, I also tried liking’s method above and it complete Cmake process then it freezes too at the end of Cmake process (I also set 8gb swapfile on SD card).

I also installed Developer version (Boot from SD card), but without GUI I’m stuck.

Thank you


#15

Hi liking,

I first tried with Mani’s instruction followed with his Github revised instruction with my setup (boot from eMMC with 8GB swapfile on SD card) and it freezes on 49% of Cmake process.

I also tried your instruction and it freezes at the end of Cmake process.

I like to try on SD card boot method (developer) but without GUI, I’m stuck.

I’m beginner and help is appreciated.

Thank you,
Martin


#16

Hey @Martin_Kim,

I always boot from eMMC. For your issue, I’m assuming that the build process (make -j4) got stuck
as opposed to cmake. cmake will just gather requirements and generate Makefile for you.

If that’s the case, can you please try to build with one thread:
$ make

Note: By default make will use single thread for build

Let us know.

Thanks,
Mani


#17

Mani,

It’s here where it got frozen "cmake -D CMAKE_BUILD_TYPE=RELEASE -DBUILD_EXAMPLES=OFF -DBUILD_opencv_apps=OFF -DBUILD_DOCS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local -DENABLE_PRECOMPILED_HEADERS=OFF -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules …/

I left it to run for over 12 hours (I know it can take some time and I learned from Pi 3) and That’s right before “make -j2” command per your Github instruction, and I have not even gone that far.

You stated on Github "Next, build OpenCV with 2 threads. -j n decides the number of threads involved in building the source. Ideally, threads should be equal to number of cores availabe in SoC. Since, DragonBoard is quad core you can have -j 4 but it may cause the CPU to overheat. So, limit to 2 inorder to avoid freeze during build.”—— I’ll try that once I got over this cmake process somehow.

I’ll try reinstall OS and retry your method over Ljking’s (was frozen too) once again and will report back.

And also "https://github.com/96boards/projects/tree/master/home_surveillance/part-2#22-package-dependencies” is not accessible anymore.

Thank you very much for quick response and support.

Martin,


#18

muffin_man,

Can you share how you were able to build on SD card please.

Thank you,

Martin


#19

Hi @Martin_Kim,

Looks like your path to OpenCV extra modules is incorrect. According to the instruction in blog:

-DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules

You seems to be missing the opencv_contrib path and directly gave /modules which is wrong.

Please include the correct path and it should work.

Thanks,
Mani


#20

Hi @Martin_Kim

I also always boot from eMMC. The SDCard is just extra file space to store the source and the intermediate objects. the install step will move all of the OpenCV libraries to the eMMC. In order to complete the build you do need a swap space, the instructions above add a 1.5GB swap space on the eMMC.

I formatted the SDCard as a ext4 partition, then built a symbolic link to it from the home directory. After that I cd to the SDCard and do the OpenCV download and build on the SDCard. The SDCard is NOT the boot device, it is just extra file system space.
To convert a SDCard to ext4 file system, first run gdisk (the last sector numbers will be different depending on the size of your SDCard, just accept the defaults)

sudo gdisk /dev/mmcblk1
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-123764702, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-123764702, default = 123764702) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):

Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y

You need to reboot the system after running gdisk.

Next build a file system on the SDCard, and link it to your home directory (you may need to reboot after the mkfs step):

sudo mkfs –t ext4 /dev/mmcblk1p1
cd /media/linaro/<long name>
sudo mkdir workspace
sudo chown linaro.linaro workspace
cd ~
ln –s /media/linaro/<long name>/workspace workspace
cd workspace

Full disclosure: I am an employee of Qualcomm Canada, any opinions I may have expressed in this or any other post may not reflect the opinions of my employer.