ubuntu: Build and install opencv

  • 2021-01-18 06:57:54
  • OfStack

Simple installation of opencv2:


conda install --channel https://conda.anaconda.org/menpo opencv

Or:


sudo apt-get install libopencv-dev python-opencv

Simple installation of opencv3:


pip install opencv-python

Or:


pip install opencv-python==3.1.0

Simple installation method is to install compiled Opencv from the library, this installation method is simple and convenient, the disadvantage is easy to appear in the use of unknown bug, such as imshow image, can not read video files, etc. (opencv3 seems to be 1 point better).

Use source code compilation installation is recommended.

Source compilation and installation of Opencv2 or Opencv3

1. Install the dependency files


sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

2. Download the source package

Official website to download address: https: / / opencv org/opencv - 3-2. html

Choose to download here GitHub source for all platforms on tar. gz file (download link: https: / / github com/opencv/opencv/archive / 3.2.0 tar. gz), opencv - 3.2.0. tar. gz, 75 MB file size

3. Unzip the source code and compile and install it


tar xvf opencv-3.2.0.tar.gz
cd opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install

ippicv_linux_20151201.tgz file is required to download. If the network is not good, it may be stuck in:

[

ICV: Downloading ippicv_linux_20151201.tgz...

]

ippicv_linux_20151201.tgz (size 36.5MB, download link: https: / / raw. githubusercontent. com/Itseez opencv_3rdparty / 81 a676001ca8075ada498583e4166079e5744668 / ippicv/ippicv_linux_20151201 tgz), After downloading on '/ opencv - 3.2.0/3 rdparty/ippicv/downloads/linux - 808 b791a6eac9ed78d32a7666804320e/' folder cmake again.

conclusion


Related articles: