一、安装opencv依赖
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
如遇libjasper-dev报错,执行如下指令
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt upgrade
sudo apt install libjasper1 libjasper-dev
opencv下载链接
解压opencv-4.5.5和opencv_contrib-4.5.5,并将解压后的放到opencv-4.5.5文件夹下
opencv-4.5.5|__build|__opencv_contrib-4.5.5
二、在opencv-4.5.5文件夹下新建build
cmake -D CMAKE_BUILD_TYPE=RELEASE \-D CMAKE_INSTALL_PREFIX=/usr/local \-D OPENCV_GENERATE_PKGCONFIG=ON .. \-D OPENCV_EXTRA_MODULES_PATH=/xxxx/opencv-4.5.5/opencv_contrib-4.5.5/modules ..
make -j8
sudo make install
三、在/etc/ld.so.conf中添加配置
sudo gedit /etc/ld.so.conf
在文件最后添加
/usr/local/lib
执行
sudo ldconfig
四、修改bash.bashrc文件
sudo gedit /etc/bash.bashrc
在文件最后添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
执行
source /etc/bash.bashrc
五、安装完测试
/xxx/opencv-4.3.0/samples/cpp/example_cmake
cmake .
make
./opencv_example