bash: 一键安装OpenCV (with Python3)

最简单的方法

在自己的python环境下,通过一条指令搞定:

pip install opencv-python

pip 会 自动 根据 当前所在的环境,为你安装好对应python版本的opencv。非常非常方便。

通过自己编译来安装

  一键 安装OpenCVbash文件 源码:



echo 'Remove old version packages'
sleep 3
sudo apt-get -y remove ffmpeg x264 libx264-dev

echo -e 'Install Dependencies'
sleep 3
sudo apt-get -y install libopencv-dev
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install libtbb-dev
sudo apt-get -y install libqt4-dev libgtk3.1-dev
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
sudo apt-get -y install x264 v4l-utils

echo -e 'Optional packages according to org'
sleep 3
sudo apt-get install libtbb2 libpng-dev libtiff-dev

echo -e 'Unzip OpenCV'
sleep 3
mkdir ~/Software/OpenCV3.3.1
unzip ../../OpenCV/opencv-3.3.1.zip -d ~/Software/OpenCV3.3.1

echo -e 'Unzipping ffmpeg'
sleep 3
tar -zxvf ../../OpenCV/ffmpeg-2.8.8.tar.gz -C ~/Software/OpenCV3.3.1

echo -e 'Mv OpenCV3.3.1/OpenCV-3.3.1/* to OpenCV3.3.1/'
sleep 3
mv ~/Software/OpenCV3.3.1/opencv-3.3.1/* ~/Software/OpenCV3.3.1/
rm -r ~/Software/OpenCV3.3.1/opencv-3.3.1/

# 将 Anaconda3/ 暂时移至回收站
echo -e 'Must move Anaconda3 to Trash temporary ! '
sleep 3
mv ~/anaconda3 ~/.local/share/Trash

echo -e 'Replace ippicv'
sleep 3

mkdir ~/Software/OpenCV3.3.1/3rdparty/ippicv/downloads/
mkdir ~/Software/OpenCV3.3.1/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/
cp ../../OpenCV/ippicv_linux_20151201.tgz ~/Software/OpenCV3.3.1/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz

echo -e 'Generate Makefile'
sleep 3
mkdir ~/Software/OpenCV3.3.1/build
cd ~/Software/OpenCV3.3.1/build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON  -D CUDA_GENERATION=Kepler  -D WITH_FFMPEG=ON ..

echo -e 'Compile'
sleep 3
cmake ..
make -j8
# 编译完后会要求再次输入密码,所以脚本运行到这里就会停掉,等待input
sudo make install

pkg-config --modversion opencv

# 将 Anaconda/ 从回收站restore
echo -e 'Restore Anaconda3 ! '
sleep 3
mv ~/.local/share/Trash/anaconda3 ~/anaconda3

cp /usr/local/lib/python3.6/dist-packages/cv2.so ~/anaconda3/lib/python3.6/site-packages/

echo "OpenCV 3.3.1 ready to be used"


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值