Ubuntu system configuration OpenCV ---

Ubuntu system configuration OpenCV ---

table of Contents

A, Ubuntu lower with OpenCV

Two, Ubuntu with the python-opencv

 

Explanation

  The above-described one, two two methods, there are still differences OpenCV arranged. According to their individual understanding of existing knowledge, " Ubuntu with OpenCV under " download system is in a opencv, OpenCV library full; " with python-opencv under Ubuntu " is a Python can call the relevant OpenCV library, OpenCV libraries incomplete, only with the python.

 

text

A, Ubuntu lower with OpenCV

  @https://blog.csdn.net/baidu_34971492/article/details/81665538

  Download the installation package, perform the installation step by step.

  (1) In Opencv official website to download OpenCV3.4.2 Sources, URL link: https: //opencv.org/releases.html, decompression.

  (2) Installation and cmake dependent libraries.

1. Quick Install cmake (you can also download the installation package cmake installed) 
sudo APT- GET install cmake cmake # View installed version: cmake --version #https: //www.cnblogs.com/zhangjiansheng/p/7990028.html APT the sudo - GET Update 2. dependencies the sudo APT - GET the install Build- Essential the sudo APT - GET . CMake the install Git libgtk2 0 -dev PKG-config with libavformat the libavcodec-dev-dev libswscale- dev the sudo APT - GET the install Python-dev Python dev libjpeg-libtbb2 libtbb -numpy-dev-dev the libtiff the libpng-dev-dev libdc1394- libjasper 22 is -dev

  (3) OpenCV3.4.2 installation. (Premise has been installed cmake: sudo apt-get install cmake)

(3.1) to create a build folder
mkdir build cd build

(3.2) cmake about
#cmake = -D CMAKE_BUILD_TYPE Release CMAKE_INSTALL_PREFIX = -D / usr / local ..
#cmake -D CMAKE_BUILD_TYPE the RELEASE = -D CMAKE_INSTALL_PREFIX = ~ / OpenCV-3.4. . 1 / build / OFF = Installed -DWITH_CUDA .. (established opencv-3.4.1 / build / installed these folders )
CMake = -D CMAKE_BUILD_TYPE Release CMAKE_INSTALL_PREFIX = -D / usr / local / opencv3.4.2 ..

Note: If you have compiled in a new folder, but will appear before an error, then compile the cmakecache.txt deleted can
not error, continue. . .

(3.3) make it
sudo make
after sudo make install # completes OpenCV compilation process is over

(3.4) to configure some of OpenCV build environment
The first step: the system environment
1. First, add the path to the OpenCV library, which allows the system to find:
sudo gedit /etc/ld.so.conf.d/opencv.conf

2. only need to add at the end of the file:
/ usr / local / lib 

3. makes the configuration path just to take effect:
sudo ldconfig

Step Two: configure bash
1. open bash.bashrc

sudo gedit /etc/bash.bashrc # sudo gedit ~ /. bashrc

2. Add the rearmost
# @ multivariate OpenCV switching https://blog.csdn.net/learning_tortosie/article/details/80594399
#export PKG_CONFIG_PATH = ~ / opencv- 3.4. . 1 / Build / Installed / lib / the pkgconfig
# the LD_LIBRARY_PATH = ~ Export / opencv- 3.4. . 1 / Build / Installed / lib
PKG_CONFIG_PATH = Export /usr/local/opencv3.4.2/lib/pkgconfig 
Export the LD_LIBRARY_PATH = /usr/local/opencv3.4.2/lib

3. validate the configuration
Source Source # /etc/bash.bashrc ~ / .bashrc

(3.5 of) the query OpenCV version
pkg-config --modversion opencv # 3.4.2 If the output, it indicates that the configuration is successful. If the preceding is not an error, the output is not 3.4.2, may not be configured to take effect, restart the computer
也可以:@https://blog.csdn.net/cocoaqin/article/details/78376382
配置.bashrc

echo '/usr/local/lib' | sudo tee -a /etc/ld.so.conf.d/opencv.conf sudo ldconfig printf '# OpenCV\nPKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig\nexport PKG_CONFIG_PATH\n' >> ~/.bashrc source ~/.bashrc

  (4) OpenCV3.4.2 test installation was successful

  Test 1:

  cd to opencv3.4.2 / samples / cpp / under example_cmake directory, the directory has been given an official of cmake example, can be used to test, performed in this order:

cmake .
make
./opencv_example

  Open the camera see, there is a hello opencv in the upper left corner, it means that the configuration is successful.

  Test 2:

  @https: //blog.csdn.net/cocoaqin/article/details/78376382 (not practical)

 

The process of recording:

 

Two, Ubuntu with the python-opencv

   查看系统中的python版本,应该有Python2.x 和 Python3.x, 切换到python3.x下(想配 python3.x + OpenCV3.4.2)。

  (1)若无pip,先安装pip3,执行命令: sudo apt install python3-pip

  (2)安装依赖项,安装libopencv-dev依赖包,运行命令: sudo apt install libopencv-dev

  (3)安装opencv-python库
    因为系统中已经安装了python3和pip3,所以直接运行。

         1. 直接安装最新版:sudo pip3 install opencv-python

    2. 或者可以进行指定版本安装:pip3 install opencv_python==版本号
    由于我这里是安装opencv3.4.2,目前的最新版是3.4.2.16
    所以直接执行:pip3 install opencv_python==3.4.2.16

  (4)  成功之后,运行python3,进入编译界面,导入库查看版本print(cv2._version__)

python3

import cv2

cv2.__version__

 

Guess you like

Origin www.cnblogs.com/carle-09/p/11263274.html