How to compile and build openCV on Raspbian - opencv

I am trying to compile and build OpenCV 2.4.13.6 in a local folder on Raspbian.
I did
cmake -D CMAKE_INSTALL_PREFIX=./ - DCMAKE_BUILD_TYPE=Debug ../
make -j4
make install
However the modules folders in the build directory were not present (for example the file core_c.h of the core module could not be found). So I tried to rerun make install but it was failing. I went back another step and rerun cmake ... I noticed it gives me warnings about many packages that cannot be found such as gtk+-2.0 gthread g-streamer and much more.
Should I install those packages to build opencv manually?

Yes, you need to install dependencies manually before compiling OpenCV, although you asked for OpenCV 2, an example list of dependencies for Raspbian can be found here. Directly quoting from given link:
Step 1:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update (can be skipped, but recommended) (don't do it if you will use the RPI cam as recommended by official RPI Website)
$ sudo reboot now
Step 2:
$ sudo apt-get install build-essential cmake pkg-config
Step 3:
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
Step 4:
$ sudo apt-get install libgtk2.0-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libv4l-0 libv4l-dev
Step 5:
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
Step 6:
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python-numpy python-scipy python-matplotlib
$ sudo apt-get install default-jdk ant
$ sudo apt-get install libgtkglext1-dev
$ sudo apt-get install v4l-utils
Step 7:
install pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
Step 8:
$ sudo apt-get install python2.7-dev
Step 9:
$ sudo pip install numpy

Related

How to upgrade cURL to 7.71.0 in a docker image with centos7.x as the base

Title is pretty self explanatory, when using yum upgrade curl it doesn't upgrade curl beyond 7.29.0 witch is an issue because I need to use the --retry-all-errors flag in the docker images startup script.
Running the below commands solved my issue
sudo rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/city-fan.org-release-2-2.rhel7.noarch.rpm
sudo yum install -y yum-utils
sudo yum-config-manager --disable city-fan.org
sudo yum -y --enablerepo=city-fan.org install libcurl libcurl-devel
If using the city-fan repo is an issue for you, you can also use this script to install directly from curl.
sudo yum install wget gcc openssl-devel make -y
wget https://curl.haxx.se/download/curl-${VERSION}.tar.gz
tar -xzvf curl-${VERSION}.tar.gz
rm -f curl-${VERSION}.tar.gz
cd curl-${VERSION}
./configure --prefix=/usr/local --with-ssl
make
sudo make install
sudo ldconfig

install Erlang 17.3 on Ubuntu 18

I was trying many ways in order to install Erlang 17.3 on Ubuntu 18. So far I came up with this solution you can read below:
For installation Erlang 17.3 on Ubuntu 18 you should do the following things:
Enter in the console next command:
Download the tar file:
wget http://erlang.org/download/otp_src_17.3.tar.gz
Extract the tar file in directory where you download the otp_src_17.3.tar.gz:
cd '/home/yaroslav/otp_src_17.3'
tar -zxf otp_src_17.3.tar.gz
set export ERL_TOP your 'pwd' path:
export ERL_TOP=pwd
Basic dependencies:
sudo apt-get install autoconf libncurses-dev build-essential
Other applications dependencies
sudo apt-get install m4
sudo apt-get install unixodbc-dev
sudo apt-get install libssl-dev
sudo apt-get -y install libssh-dev
sudo apt-get install libwxgtk3.0-dev libglu-dev
sudo apt-get install fop xsltproc
sudo apt-get install g++
sudo apt-get install default-jdk
sudo apt-get install xsltproc fop
Or all dependencies in one line:
apt-get -y install build-essential autoconf m4 libncurses5-dev libwxgtk3.0-dev libgl1-mesa-
dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop g++ default-jdk
install openssl version 1.0.2 for Ubuntu 18 (different version SSL is not compatible):
curl https://www.openssl.org/source/openssl-1.0.2l.tar.gz | tar xz && cd openssl-1.0.2l &&
sudo ./config && sudo make && sudo make install
Configure and build:
./configure --with-ssl='/home/yaroslav/otp_src_17.3/openssl-1.0.2l'
sudo make
sudo make install
For installing older versions of Erlang and working with several at the same time I would recommend using kerl
If you need more fancy features you could also head for asdf which has a Erlang plugin (which runs kerl under the hood)

Importing openCV in python idle error: shared object file

I have been trying to use the cv2 library in python (in IDLE on raspberry pi 3) but I can't manage to import it successfully.
when I type import cv2, I get this:
Traceback (most recent call last):
File "/home/pi/Desktop/python/test.py", line 2, in <module>
from .cv2 import *
ImportError: libjasper .so.1: cannot open shared object file: No such file or directory
I have used the terminal to update, upgrade, and install opencv along with pretty much every other thing I could find relating to opencv or lib. I currently can import cv2 in the terminal but not in IDLE. What do I need to do to be able to import the cv2 library? Thanks in advance.
Recommended way of installing opencv on linux as given by opencv docs "https://docs.opencv.org/4.2.0/d2/de6/tutorial_py_setup_in_ubuntu.html" for python3 is:
sudo apt install python3-opencv
for python2:
sudo apt install python-opencv
On Raspberry pi you may occasionally need to run:
sudo apt update --fix-missing
It will auto-install all the dependencies.
As discussed here, below installations seemed to resolve the issue. It worked for me.
pip3 install opencv-python
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt-get install python3-pyqt5
sudo apt-get install libqt4-test
Or
the newer OpenCV version handles other installations themselves.
pip install opencv-python==4.1.2.30
Follow the commands for opencv and face recognition : (it worked for me)
-> sudo apt update
-> sudo apt upgrade
-> sudo apt-get install python3-pip
pi#raspberrypi:~ $ python3 -V
Python 3.5.3
pi#raspberrypi:~ $ python2 -V
Python 2.7.13
-> pip3 install numpy
-> pip3 install pillow
-> pip3 install dlib
-> sudo apt-get install cmake
-> pip3 install face_recognition
-> sudo apt-get install python-opencv
-> sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev
-> sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
-> sudo apt-get install libatlas-base-dev
-> sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev -y
-> sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
-> sudo apt-get install libgtk2.0-dev libgtk-3-dev -y
-> sudo pip3 install opencv-python
-> sudo apt-get install libavformat-dev libswscale-dev openexr libopenexr-dev
-> sudo apt-get install libqt4-dev
-> sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
pi#raspberrypi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import dlib
>>> import face_recognition
>>>
Depends on the system.
for PI will take : 2 to 3 hr. (total time)
thanks :)

Installing OpenCV in Tinker Board

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 : 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?
I successfully managed to install OpenCV on a TinkerBoard. The following were the steps:
Format a 16 GB memory card to FAT32
Download debian image 20170817-tinker-board-linaro-stretch-alip-v2.0.1.img for tinker board from here.
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.
Before powering on ensure that you connect your tinker board to the internet through a lan cable.
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.
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'
After few days finally I got good setup. My post improves the previous answer.
Steps is similar like it was before me, but I changed few strings, because I had different errors.
In my case for new Asus Tinker Board I installed:
20170928-tinker-board-linaro-stretch-alip-v2.0.3
opencv-3.3.0 with opencv_contrib-3.3.0.
First start of tinker board.
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
It necessary to remove default (old) OpenCV:
sudo apt-get remove libopencv*
sudo apt-get -y autoremove
# INSTALL THE DEPENDENCIES
# Build tools:
sudo apt-get install -y build-essential cmake
# GUI (I had errors with Qt, so I did next)
sudo apt-get install -y libgtkglext1-dev libvtk6-dev
# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libopenexr-dev libgdal-dev
# 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 libxine-dev
sudo apt-get install -y gstreamer1.0-plugins-*
# 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.
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.3.0.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.3.0.zip
unzip opencv_contrib.zip
Compile and Install OpenCV
cd ~/opencv-3.3.0/
mkdir build
cd build
cmake -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_FFMPEG=0 -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules -DENABLE_PRECOMPILED_HEADERS=OFF ..
CMake should start to build your configuration, after a couple of minutes you should see:
-- Configuring done
-- Generating done
-- Build files have been written to: ./opencv-3.3.0/build
If you can't see Generating done then some issues have been occurred. Read error messages and the error log file to investigate.
I did without examples, but you can try. Qt I deleted.
make
Better without -j4.
sudo make install
sudo ldconfig
Test the installation
linaro#tinkerboard:~$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.0'
installing ffmpeg ( the previous answers skiped this )
sudo apt update && sudo apt install ffmpeg libav-tools x264 x265
I also recommend installing the additional packages and enabling neon and vfpv3 when compiling the opncv files. This should give significant improvement in performance:
https://www.pyimagesearch.com/2017/10/09/optimizing-opencv-on-the-raspberry-pi/
I came to this question late. I am adding this answer for the future reference of the people. Here is the official documentation of Tinkerboard.
https://tinkerboarding.co.uk/wiki/index.php/CSI-camera
I just changed the version to the latest version at this time (3.4.1):
#!/bin/bash
#Install
sudo apt-get update
sudo apt-get upgrade
#Install a few developer tools
sudo apt-get install -y build-essential git cmake pkg-config
#Install image I/O packages which allow us to load image file formats such as JPEG, PNG, TIFF, etc.
sudo apt-get install -y libjpeg-dev libtiff5-dev libpng-dev
#Install video I/O packages
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
#Install the GTK development library
sudo apt-get install -y libgtk2.0-dev
#Various operations inside of OpenCV (such as matrix operations) can be optimized using added dependencies
sudo apt-get install -y libatlas-base-dev gfortran
#Install the Python 2.7 and Python 3 header files
sudo apt-get install -y python2.7-dev python3-dev python-opencv
wget https://github.com/opencv/opencv/archive/3.4.1.zip
unzip 3.4.1.zip
cd opencv-3.4.1
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D WITH_LIBV4L=ON -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make install
It took around 90 minutes to compile.

How to install a local rpm file when building docker instance?

I have following docker file, I want to specifically install a rpm file that is available on my disk as I am building docker instance. My invocation of rpm install looks like this. Command
RUN rpm -i chrpath-0.13-14.el7.x86_64.rpm fails.
Is there a way to install rpm file available locally to new Docker instance?
FROM centos:latest
RUN yum -y install yum-utils
RUN yum -y install python-setuptools
RUN easy_install supervisor
RUN mkdir -p /var/log/supervisor
RUN yum -y install which
RUN yum -y install git
# Basic build dependencies.
RUN yum -y install autoconf build-essential unzip zip
# Gold linker is much faster than standard linker.
RUN yum -y install binutils
# Developer tools.
RUN yum -y install bash-completion curl emacs git man-db python-dev python-pip vim tar
RUN yum -y install gcc gcc-c++ kernel-devel make
RUN yum -y install swig
RUN yum -y install wget
RUN yum -y install python-devel
RUN yum -y install ntp
RUN rpm -i chrpath-0.13-14.el7.x86_64.rpm
Put this line before your rpm -i command:
ADD /host/abs/path/to/chrpath-0.13-14.el7.x86_64.rpm /chrpath-0.13-14.el7.x86_64.rpm
Then you'll be able to do
RUN rpm -i chrpath-0.13-14.el7.x86_64.rpm
As and addendum to what others have written here, rather than using:
RUN rpm -i xyz.rpm
You might be better off doing this:
RUN yum install -y xyz.rpm
The latter has the advantages that (a) it checks the signature, (b) downloads any dependencies, and (c) makes sure YUM knows about the package. This last bit is less important than the other two, but it's still worthwhile.
Suppose you have your Dockerfile available at /opt/myproject/. Then first you have to put rpm inside /opt/myproject and then add
Add /xyz.rpm /xyz.rpm
RUN rpm -i xyz.rpm

Resources