ubuntu下安装opencv4.6.0,安装后测试opencv
时间: 2023-11-08 07:55:10 浏览: 247
测试opencv是否安装好的程序
5星 · 资源好评率100%
好的,安装OpenCV 4.6.0的步骤如下:
1. 更新包管理器:
```
sudo apt update
```
2. 安装依赖项:
```
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
```
3. 克隆OpenCV仓库:
```
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.6.0
```
4. 创建并进入build目录:
```
cd ..
mkdir build
cd build
```
5. 配置OpenCV:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=OFF \
-D WITH_CUDNN=OFF \
-D OPENCV_DNN_CUDA=OFF \
-D BUILD_opencv_python3=ON \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
```
6. 编译和安装:
```
make -j$(nproc)
sudo make install
sudo ldconfig
```
7. 测试OpenCV:
```
cd ~/opencv/samples/cpp/
g++ `pkg-config --cflags --libs opencv4` facedetect.cpp -o facedetect
./facedetect --face_cascade=../../data/haarcascades/haarcascade_frontalface_alt.xml --scale=1.3 lena.jpg
```
如果一切正常,你应该可以看到lena.jpg中的脸部被检测到了。
希望这可以帮助到你。
阅读全文