Ubuntu的opencv环境配置
时间: 2024-10-06 07:01:08 浏览: 25
OpenCV环境配置源码
Ubuntu上安装OpenCV并配置环境通常涉及几个步骤:
1. 更新系统和安装必要的依赖项:
```sh
sudo apt-get update
sudo apt-get install build-essential cmake git libgtk-3-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev x264 v4l-utils
```
2. 安装Git以便从GitHub克隆OpenCV源码:
```sh
sudo apt-get install git
```
3. 下载OpenCV源码:
```sh
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
```
4. 进入OpenCV目录:
```sh
cd opencv
```
5. 配置并编译OpenCV(选择所需模块):
```sh
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D WITH_V4L=ON \
-D BUILD_opencv_python=ON ..
make -j$(nproc)
```
6. 安装Python绑定(如有需要):
```sh
make install
pip install -i http://mirrors.aliyun.com/pypi/simple/ opencv-python
```
7. 验证安装:
```sh
python -c "import cv2; print(cv2.__version__)"
```
阅读全文