ubuntuopencv编译扩展包
时间: 2023-09-18 20:12:28 浏览: 86
编译OpenCV扩展包需要以下步骤:
1. 安装OpenCV和相关依赖项:
```bash
sudo apt-get update
sudo apt-get install build-essential 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
```
2. 下载OpenCV的源代码:
```bash
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout <version> # 替换version为你想要编译的OpenCV版本号
```
3. 编译OpenCV:
```bash
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
sudo make install
```
4. 下载并编译OpenCV的扩展包:
```bash
cd ~/Downloads # 可以替换为你想保存源代码的路径
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout <version> # 替换version为你想要编译的OpenCV版本号
cd ..
mkdir build_contrib
cd build_contrib
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
make -j$(nproc)
sudo make install
```
注意:在编译OpenCV的扩展包时,需要指定OpenCV的路径。如果你的OpenCV安装在非默认路径(/usr/local)下,需要使用`-D OpenCV_DIR=/path/to/opencv/build`指定路径。
阅读全文