Install OpenCV C++ on Ubuntu system

1. Update the system

sudo apt-get update
sudo apt-get upgrade

2. Install related dependencies

sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libatlas-base-dev gfortran

3. Download OpenCV

git clone https://github.com/opencv/opencv.git

4. Enter the path where OpenCV is located

cd opencv
mkdir build

5. Compile and install
Enter the following commands in sequence:

cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install
sudo nano /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
g++ -o test_opencv test_opencv.cpp `pkg-config opencv --cflags --libs`
./test_opencv

The program runs successfully, which means the installation is successful

Guess you like

Origin blog.csdn.net/weixin_47665864/article/details/130196900