Compile and install OpenCV3.4.5 steps under ubuntu16.04 (super detailed)

One, the compilation process of OpenCV3.4.5

1. First download the source version of OpenCV 3.4.5 on the OpenCV official website

2. Decompress the downloaded compressed package

unzip opencv-3.4.5.zip

3. Enter the opencv-3.4.5 folder and install the corresponding dependent libraries

cd opencv-3.4.5
sudo apt-get update
sudo apt-get install cmake
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev  

4. After installing the dependent library, create a compilation folder and enter the compilation folder

mkdir opencv_build_dir
cd opencv_build_dir

5. cmake configuration compilation

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

The result of the compilation is as follows: 

6. Perform the compilation process 

sudo make

The result after compilation is as follows:

7. Execute the following installation commands

sudo make install

The results are as follows:

 

After the above execution is completed, the OpenCV3.4.5 compilation process is all over.

2. Configure OpenCV3.4.5 compilation environment

1. Add the OPenCV library to the path so that the system can find it

sudo gedit /etc/ld.so.conf.d/opencv.conf

After executing this command, it may be a blank document. You don’t need to worry about it, just add the following statement to the end.

/usr/local/lib 

Execute the following command to make the path configured just now take effect

sudo ldconfig

2. Configure bash

sudo gedit /etc/bash.bashrc

在打开的文件最后换行添加以下命令

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
export PKG_CONFIG_PATH 

保存,执行以下命令使得配置生效
source /etc/bash.bashrc 


最后进行更新

sudo updatedb

Three, verify that OpenCV 3.4.5 is installed successfully

1. Enter the example_cmake directory of the opencv directory

 2. Execute the following command

cmake .

Command line execution screenshot

 3. Execute the following command

make

The execution screenshot is as follows

4. Execute the following command, you can see that the program opens the camera and displays a hello opencv word in the upper left corner, indicating that the configuration is successful. 

./opencv_example

 

Guess you like

Origin blog.csdn.net/qq_40716944/article/details/109092616