【转】ubuntu 安装 OpenCv 4.6脚本 installOCV.sh

摘自 https://github.com/opencv/opencv/issues/22132

好东西,收一下。

bash 复制代码
installOCV.sh

#! /bin/bash
VER=4.6.0
PYTHON_VERSION=3.8
CORES=2
echo "Script for installing the OpenCV $VER on Ubuntu 18.04 LTS"
echo "Updating the OS..."
sudo apt update 
sudo apt upgrade -y
echo "Installing dependencies..."
sudo apt install build-essential cmake unzip pkg-config -y
sudo apt install libjpeg-dev libpng-dev libtiff-dev -y
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
sudo apt install libxvidcore-dev libx264-dev -y
sudo apt install libgtk-3-dev -y
sudo apt install libatlas-base-dev gfortran -y
sudo apt install python3-dev libtbb-dev -y
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libavresample-dev -y
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev -y
sudo apt install libxvidcore-dev x264 libx264-dev libfaac-dev libmp3lame-dev libtheora-dev -y
sudo apt install libfaac-dev libmp3lame-dev libvorbis-dev -y
sudo apt install libdc1394-22 libdc1394-22-dev libxine2-dev libv4l-dev v4l-utils -y
sudo apt install libprotobuf-dev protobuf-compiler -y
sudo apt install libgoogle-glog-dev libgflags-dev -y
sudo apt install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen -y
sudo apt install python-is-python3
echo "Fetching and unpacking OpenCV $VER..."
mkdir -p $HOME/repositories
cd $HOME/repositories
wget -O opencv.zip https://github.com/opencv/opencv/archive/${VER}.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${VER}.zip
#wget https://bootstrap.pypa.io/get-pip.py
#sudo python3 get-pip.py
sudo -H pip3 install numpy matplotlib imutils -U
unzip opencv.zip
unzip opencv_contrib.zip
rm opencv.zip
rm opencv_contrib.zip
cd opencv-${VER}
mkdir -p build
cd build

echo "Compiling OpenCV $VER... this will take several minutes..."
rm CMakeCache.txt
hostname=$(sudo cat /etc/hostname)
cmake -D CMAKE_BUILD_TYPE=RELEASE \
	-D CMAKE_INSTALL_PREFIX=/usr/local \
	-D INSTALL_PYTHON_EXAMPLES=OFF \
	-D INSTALL_C_EXAMPLES=OFF \
	-D OPENCV_ENABLE_NONFREE=ON \
	-D OPENCV_EXTRA_MODULES_PATH=~/repositories/opencv_contrib-${VER}/modules \
	-D BUILD_NEW_PYTHON_SUPPORT=ON \
	-D PYTHON3_PACKAGES_PATH=/usr/local/lib/python${PYTHON_VERSION}/dist-packages \
	-D BUILD_opencv_python3=ON \
	-D PYTHON_DEFAULT_EXECUTABLE=$(which python3) \
	-D OPENCV_GENERATE_PKGCONFIG=ON \
	-D OPENCV_PC_FILE_NAME=opencv4.pc \
	-D WITH_TBB=ON \
	-D ENABLE_FAST_MATH=1 \
	-D CUDA_FAST_MATH=1 \
	-D WITH_CUBLAS=1 \
	-D WITH_CUDA=ON \
	-D BUILD_opencv_cudacodec=OFF \
	-D WITH_CUDNN=ON \
	-D OPENCV_DNN_CUDA=ON \
	-D CUDA_ARCH_BIN=7.5 \
	-D WITH_V4L=ON \
	-D WITH_QT=OFF \
	-D WITH_OPENGL=ON \
	-D WITH_QT=OFF \
	-D WITH_GSTREAMER=ON \
	-D WITH_FFMPEG=ON \
	-D WITH_OPENCL=ON \
	-D OPENCV_ENABLE_NONFREE=ON \
	-D ENABLE_PRECOMPILED_HEADERS=YES \
	-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
	-D BUILD_EXAMPLES=ON ..
echo "Compilation has started ..."
make -j$CORES
echo "Installing OpenCV $VER ..."
sudo make -j$CORES install
sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/
sudo cp unix-install/opencv4.pc /usr/local/lib/pkgconfig
sudo ldconfig
source $HOME/.bashrc
echo "Installation complete"
相关推荐
不是三毛没有半22 分钟前
Centos 7 安装wget
linux
天飓35 分钟前
基于OpenCV的自制Python访客识别程序
人工智能·python·opencv
叫我龙翔1 小时前
【计网】实现reactor反应堆模型 --- 多线程方案优化 ,OTOL方案
linux·运维·网络
mit6.8241 小时前
[Docker#9] 存储卷 | Volume、Bind、Tmpfs | -v/mount | MySQL 灾难恢复 | 问题
linux·运维·docker·容器·架构
WangYaolove13141 小时前
请解释Python中的装饰器是什么?如何使用它们?
linux·数据库·python
7yewh2 小时前
嵌入式硬件实战提升篇(一)-泰山派RK3566制作多功能小手机
linux·arm开发·驱动开发·嵌入式硬件·物联网·智能手机·硬件架构
YRr YRr2 小时前
ubuntu ros 解决建完图后 保存的地图非常小的问题
linux·运维·ubuntu
脸ル粉嘟嘟3 小时前
常用命令之Linux&Oracle&Hive&Python
linux·hive·oracle
Wils0nEdwards3 小时前
Leetcode 整数转罗马数字
linux·python·leetcode
五味香3 小时前
Linux学习,ip 命令
linux·服务器·c语言·开发语言·git·学习·tcp/ip