ubuntu1604+opencv346 configuration


foreword

I recently need to do visual-related development under ubuntu. I used to use vs2017 for development in windows before. Now in ubuntu, vs can’t be used, only vscode or qt can be used. There are many recommended vscode on the Internet, so I plan to configure opencv in vscode.
My environment is ubuntu16+vscode+opencv3.4.6

1. opencv3.4.6

#1. Installation
1. Go to the official website to download opencv. This tutorial installs opencv3.4.6, and the installation of other versions is similar. Download the link , select the source version
2. Unzip the download and print the compressed package

cd xxx //转到文件路径
unzip opencv3.4.6.zip//解压

3. Install dependent libraries
This step can be said to be the most error-prone. If this step is not done well, various errors will be reported when cmake is executed later, such as no package can be found.
The most serious thing is that cmake is fine, but when you run the code that contains the opencv library, an error is reported, then you need to uninstall and reinstall. Not much to say, start installing dependent libraries

sudo apt-get update
sudo apt-get install vim
sudo apt-get install g++
sudo apt-get install gcc
sudo apt-get install cmake
sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev
sudo apt-get install libavcodec-dev
sudo apt-get install libavformat-dev
sudo apt-get install libswscale-dev 
sudo apt-get install libatlas-base-dev 
sudo apt-get install gfortran
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get update
sudo apt-get install libjasper1 libjasper-dev

In addition, you may need to install some other libraries. This article is very detailed
. In order to prevent uninstallation and reinstallation, it is recommended to download all dependencies that need to be downloaded if there is a problem in this blog.
After installing the above dependencies, some users may have problems when calling opencv at the end (such as me). The specific problem is that 在这里插Thefunction is not implemented. Rebuild the library with Windows, GTK+ 2.x orCarbon support. If you are on Ubuntu or Debian, install libgtk2.0‑dev and pkg
this problem only occurs when you call imshow, and there is no problem calling other codes. The reason is that qt5 is not installed, so you need to uninstall and reinstall, and install qt5 before reinstalling

sudo apt-get install qt5-default

4. Enter the decompressed file package and create a compilation folder

cd XXX/opencv-3.4.6
mkdir Release
cd Release

5.CMAKE

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

The cmake statement here is the one I installed and used for the first time. After reporting an error, I used the following statement to compile qt into it.

cmake -D CMAKE_BUILD_TYPE=Release -D WITH_QT=ON WITH_GTK = ON WITH_GTK_2_X =ON -D CMAKE_INSTALL_PREFIX=/usr/local ..

In this way, there will be no problem
6. Start make later

sudo make
sudo make install

7. After the execution is completed, 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

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

It may be a blank file opened after executing this command, don’t worry about it, just add at the end of the file

/usr/local/lib  

8. Execute the following command to make the configuration path just take effect

sudo ldconfig  

10. configure bash

sudo gedit /etc/bash.bashrc  

Add at the end

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

Save and execute the following command to make the configuration take effect

source /etc/bash.bashrc  

renew

sudo updatedb  

Two, test

cd to the opencv-3.4.1/samples/cpp/example_cmake directory,
we can see that the official has given a cmake example in this directory, we can use it for testing

cd ..
cd samples
cd cpp
cd example_cmake
cmake .
make
./opencv_example

Summarize

For the time being, this will be the case first, and the configuration of vscode will be added later.
Refer to the blog blog

Guess you like

Origin blog.csdn.net/bookshu6/article/details/121827332