在Ubuntu中配置OpenCV环境可以按照以下步骤进行:
安装依赖项:
sudo apt-get update
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 python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
下载OpenCV源代码:
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.5.1
创建一个build目录并进入:
mkdir build
cd build
使用CMake进行配置:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
编译和安装:
make -j$(nproc)
sudo make install
配置库路径:
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
验证安装:
pkg-config --modversion opencv4
以上步骤将会在Ubuntu中安装和配置OpenCV环境。