Ubuntu系统上安装OpenCV C++

2024-01-17 17:23:08 浏览数 (3)

1.更新系统

代码语言:javascript复制
sudo apt-get update
sudo apt-get upgrade

2.安装相关的依赖

代码语言:javascript复制
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.下载OpenCV

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

4.进入到OpenCV所在的路径

代码语言:javascript复制
cd opencv
mkdir build

5.编译安装 依次输入如下命令:

代码语言:javascript复制
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

程序运行成功,代表安装成功

0 人点赞