ubuntu下安装opencv4.6.0,安装后测试opencv
时间: 2023-11-08 17:15:22 浏览: 38
安装OpenCV 4.6.0的步骤如下:
1. 安装依赖项:
```
sudo apt update
sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libv4l-dev libxvidcore-dev libx264-dev
```
2. 下载OpenCV 4.6.0源代码:
```
cd ~
mkdir opencv_build && cd opencv_build
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.6.0
```
3. 编译和安装OpenCV:
```
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8
sudo make install
```
4. 配置OpenCV环境变量:
```
echo 'export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig' >> ~/.bashrc
source ~/.bashrc
```
5. 测试OpenCV:
```
cd ~
wget https://github.com/opencv/opencv/raw/master/samples/data/lena.jpg
cd opencv_build/opencv/build/bin
./opencv_version
./cpp-example-display-image lena.jpg
```
如果安装和配置都成功,你应该能够看到OpenCV版本信息和lena图像。
阅读全文