安装opencv3.4.0linux命令
时间: 2023-11-29 08:38:15 浏览: 101
opencv340.zip
很高兴为您提供帮助!以下是安装OpenCV 3.4.0的Linux命令:
1. 更新和升级Ubuntu系统:
sudo apt-get update
sudo apt-get upgrade
2. 安装必需的软件包:
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
3. 下载OpenCV 3.4.0:
cd ~/
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.0.zip
unzip opencv.zip
4. 下载OpenCV贡献模块:
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.0.zip
unzip opencv_contrib.zip
5. 安装Python2相关的软件包:
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev python-opencv python-pip
6. 安装Python3相关的软件包:
sudo apt-get install python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev python3-opencv python3-pip
7. 编译和安装OpenCV 3.4.0:
cd ~/opencv-3.4.0/
mkdir build
cd build
# for Python 2
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_python2=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.0/modules -D BUILD_EXAMPLES=ON ..
# for Python 3
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_python3=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.0/modules -D BUILD_EXAMPLES=ON ..
# compile and install
make -j8
sudo make install
注意:此过程可能需要一些时间,请耐心等待。完成后,您可以通过执行以下命令来验证OpenCV是否正确安装:
python
import cv2
print(cv2.__version__)
如果您看到OpenCV 3.4.0的版本号,则表示已成功安装!希望这可以解决您的问题!
阅读全文