Reprinted from: https://blog.csdn.net/cocoaqin/article/details/78163171
Thanks for the blogger's contribution.
Keep it for yourself and your friends to solve the problem in case of environmental problems...
Due to a problem with ubuntu on the computer, it has been reinstalled once, and the link to uninstall OpenCV is attached:
https://blog.csdn.net/qq_29229045/article/details/78527391
Pro-test is valid, OpenCV 3.4.0, 3.4.1 are applicable
1. Go to the official website to download opencv. In this tutorial, opencv3.4.1 is selected. The configuration methods of other versions are similar.
Download link http://opencv.org/releases.html , select the sources version
2. Unzip the downloaded zip package
unzip opencv-3.4.1.zip
- 1
3. Enter the decompressed file package
4. Install dependent libraries and cmake. If you are reminded that apt-get update is required, first sudo su to enter root privileges, then sudo apt-get update, and then execute the following command
sudo apt-get install cmake
- 1
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
- 1
5. After installing cmake, execute the command to create a compilation folder. If it is not created, it will prompt (as shown below)
In-source builds are not allowed.
mkdir my_build_dir
cd my_build_dir
- 1
- 2
6. cmake
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
- 1
Note: If it has been compiled in a new folder, but the previous error still occurs, delete cmakecache.txt and compile it again.
During the period, something may be downloaded, wait for a while and it will be OK
7. Execute the command, the long compilation process
sudo make
- 1
8. Execute the command
sudo make install
- 1
9. 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 gedit /etc/ld.so.conf.d/opencv.conf
- 1
After executing this command, it may be a blank file, don't care, just add at the end of the file
/usr/local/lib
- 1
10. Execute the following command to make the previous configuration path take effect
sudo ldconfig
- 1
这个时候可能会提示错误如下图所示(上部分)
sbin/ldconfig.real: /usr/lib/nvidia-375/libEGL.so.1 不是符号连接
/sbin/ldconfig.real: /usr/lib32/nvidia-375/libEGL.so.1 不是符号连接
出现这个错误可能是由于系统BUG所致
只需要分别输入上面图下部分的四行命令就可解决
sudo mv /usr/lib/nvidia-375/libEGL.so.1 /usr/lib/nvidia-375/libEGL.so.1.org
sudo mv /usr/lib32/nvidia-375/libEGL.so.1 /usr/lib32/nvidia-375/libEGL.so.1.org
sudo ln -s /usr/lib/nvidia-375/libEGL.so.375.39 /usr/lib/nvidia-375/libEGL.so.1
sudo ln -s /usr/lib32/nvidia-375/libEGL.so.375.39 /usr/lib32/nvidia-375/libEGL.so.1
11.配置bash
sudo gedit /etc/bash.bashrc
- 1
在最末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
- 1
- 2
保存,执行如下命令使得配置生效
source /etc/bash.bashrc
- 1
更新
sudo updatedb
- 1
12.至此所有的配置都已经完成
下面用一个小程序测试一下
找到
cd到opencv-3.4.1/samples/cpp/example_cmake目录下
我们可以看到这个目录里官方已经给出了一个cmake的example我们可以拿来测试下
按顺序执行
cmake .
make
./opencv_example
- 1
- 2
- 3
You can see that the camera is turned on, and there is a hello opencv in the upper left corner
, which means the configuration is successful