Reference https://www.cnblogs.com/arkenstone/p/6490017.html
https://blog.csdn.net/u013180339/article/details/77507936
The installation here is not installed with pip or conda. Opencv installed through pip or conda only encapsulates the Python API of opencv, which is generally sufficient. However, if you are going to install the full version of opencv, it is recommended to uninstall opencv-python to avoid unnecessary errors later.
1. Configure the environment
$ 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 # packages needed to process images $ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev $ sudo apt - get install libxvidcore-dev libx264- dev # packages needed to process video $ sudo apt - get install libatlas - base - dev gfortran # optimize opencv functions $ sudo apt-get install ffmpeg
2. Download opencv3.4.0
Here you need to download opencv and opencv_contrib (the latter will be used in cmake configuration), this is because attributes such as SIFT and SURF have been moved to contrib after opencv3
$ wget https: // github.com/opencv/opencv/archive/3.4.0.zip # Download directly from github or clone $ wget https: // github.com/opencv/opencv_contrib/archive/3.4.0 .zip
3. Configure and compile opencv (no NVIDIA CUDA version)
Unzip and install the cmake configuration properties, create a compilation folder
$ unzip 3.4.0.zip
$ cd opencv-3.4.0
$ mkdir bilud
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.0/modules \
-D PYTHON_EXCUTABLE=/usr/bin/python \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \ # 1
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D BUILD_EXAMPLES=ON .. # How the cmake command is used: cmake [< some optional parameters>] < path to the OpenCV source directory>.
If the command reports an error, you can try to remove the space after the -D and execute it once.
$ make -j4 #4 is determined according to the number of cores of your computer, my computer has 4 cores
$ sudo make install
$ sudo / bin/bash -c 'echo "/home/fanzong/anaconda2/envs/tensorflow/lib" > / etc/ld.so.conf.d/opencv.conf'
$ sudo ldconfig
PS: 1. If qt is not installed, you can delete this line;
CMAKE_INSTALL_PREFIX: The installed python directory prefix, in fact, specifies the installation path of the python module. The output of the following command is the path:
python -c "import sys; print(sys.prefix)"
PYTHON_EXCUTABLE: Specifies the path to the python execution file. The output of the following command is the path
which python
If you want to close the installation of ippicv, just add a line to the above cmake command: -D WITH_IPP=OFF \
After the above configuration command is successfully executed, continue to execute the compilation command
After sudo make install is executed, the OpenCV compilation process is over. Next, you need to configure some OpenCV compilation environments. First, add the OpenCV library to the path, so that the system can find it.
sudo vim /etc/ld.so.conf.d/opencv.conf
After executing this command, it may be a blank file, don't care, just add at the end of the file
/usr/local/lib
Execute the following command to make the previous configuration path take effect
sudo ldconfig
4. Complete the installation and test
After the installation is complete, restart the machine and check the opencv version
python -c "import cv2; print(cv2.__version__)"
If installed correctly it will output 3.4.0