Thursday 22 March 2018

Install openCV on Ubuntu 16.04

I was installing openCV following the instruction from the first google search:
          https://www.learnopencv.com/install-opencv3-on-ubuntu/

But I met the following problems so far.

sudo apt-get install git gfortran

error:
The following packages have unmet dependencies:
 gfortran : Depends: gfortran-5 (>= 5.3.1-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

solution:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gfortran-5
Now do it again and it works.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

error:
The following packages have unmet dependencies:
 libjasper-dev : Depends: libjasper1 (= 1.900.1-debian1-2.4ubuntu1) but 1.900.1-debian1-2.4ubuntu1.1 is to be installed
E: Unable to correct problems, you have held broken packages.

solution:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

Now do it again and it works.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) 
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Solution:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

~$ sudo dpkg --configure -a

Do it again and worked:
~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

~$ sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

error:
The following packages have unmet dependencies:
 libgstreamer-plugins-base0.10-dev : Depends: libglib2.0-dev but it is not going to be installed
 libgstreamer0.10-dev : Depends: libglib2.0-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Solution:
Install the dependency libglib2.0-dev:
sudo apt-get install libglib2.0-dev libglib2.0-0=2.48.0-1ubuntu4

Do it again and worked:
~$ sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev
I jumped over qt5-default, too many dependencies...so just:
~$ sudo apt-get install libgtk2.0-dev libtbb-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install python-dev python-pip python3-dev python3-pip

errors:
The following packages have unmet dependencies:
 python3-pip : Depends: python-pip-whl (= 8.1.1-2) but 8.1.1-2ubuntu0.4 is to be installed
               Recommends: python3-setuptools but it is not going to be installed
               Recommends: python3-wheel but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

solution:
Don't know yet...I jumped over python3-pip for now.

/////////////////////////////////////////////////////////////////////////////////////////////////////

OK finally cmake...but I got errors. After trying a lot to install some dependencies like qt5, I still couldn't get rid of the errors. I found the official website has a tutorial about installation:
            
                https://docs.opencv.org/trunk/d2/de6/tutorial_py_setup_in_ubuntu.html

Note that you have to delete ./build directory and create a new folder and do:
$ cmake ../

...and it worked!
..............
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
 ...................


ref:
https://www.learnopencv.com/install-opencv3-on-ubuntu/
https://askubuntu.com/questions/720948/problems-installing-gfortran
https://github.com/opencv/opencv/issues/8622
https://askubuntu.com/questions/15433/unable-to-lock-the-administration-directory-var-lib-dpkg-is-another-process
https://askubuntu.com/questions/884413/unable-to-install-libgtk2-0-dev-on-ubuntu-16-04/886022

https://docs.opencv.org/trunk/d2/de6/tutorial_py_setup_in_ubuntu.html
https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

No comments:

Post a Comment