virtualbox下ubuntu18.04安装opencv
时间: 2023-10-29 11:05:22 浏览: 143
ubuntu opencv安装
3星 · 编辑精心推荐
可以直接安装OpenCV 4.x或者OpenCV 3.x,具体步骤可以在终端中运行以下命令:
1. 更新系统软件包
sudo apt-get update && sudo apt-get upgrade
2. 安装OpenCV依赖
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base-dev python-dev python-bumpy libgstreamer-plugins-base1.0-dev libavresample-dev libgphoto2-dev libopenblas-dev libwebp-dev libatlas-base-dev liblapack-dev libblas-dev libeigen3-dev libhdf5-dev libprotobuf-dev protobuf-compiler libgoogle-glog-dev libgflags-dev libtbb2 libtbb-dev libdc1394-22-dev libvorbis-dev libogg-dev libtheora-dev libx264-dev libxvidcore-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev libprotobuf-dev protobuf-compiler libgoogle-glog-dev libgflags-dev libtesseract-dev -y
3. 下载OpenCV源码
cd ~
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.0.0
4. 编译并安装OpenCV
cd ~
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_opencv_python3=ON -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_ENABLE_NONFREE=ON -D WITH_CUDA=OFF -D WITH_CUDNN=OFF -D WITH_OPENGL=ON -D WITH_OPENCL=ON -D WITH_IPP=ON -D WITH_TBB=ON -D WITH_EIGEN=ON -D WITH_DNN=ON -D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D WITH_GSTREAMER_0_10=OFF -D WITH_OPENEXR=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so -D PYTHON3_INCLUDE_DIR=/usr/include/python3.6m -D PYTHON3_EXECUTABLE=/usr/bin/python3 -D BUILD_EXAMPLES=ON ..
make -j8
sudo make install
安装完成后,你可以尝试使用以下命令测试是否安装成功:
python3
import cv2
print(cv2.__version__)
阅读全文