ubuntu上OpenCv安装及范例
Talk is cheap. Show you the code!
#!/bin/bash
# author: Cheng
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake git pkg-config #开发包
sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev #图像I/O包
sudo apt-get install libgtk2.0-dev #GUI显示包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev #视频处理包
sudo apt-get install libatlas-base-dev gfortran #OpenCv内部优化包
sudo apt-get install python2.7-dev #Python开发工具
sudo pip install numpy #numpy包
cd ~
mkdir opencvworkbench
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 3.0.0
cd ..
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib
git checkout 3.0.0
cd ../opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig
python -c ""
—————————————分割线————————————————————————
Looks stupid!
直接用Python就可以装Opencv3.3.0版本的。
sudo pip3 install opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple
还贼快!
具体可以参看https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961这个地方如何完整编译。
------------分割线----------------------
上述的方法导致cv2.VideoCapture()
不好用。最好的方法还是自己编译一遍,,,详见https://github.com/BVLC/caffe/wiki/OpenCV-3.3-Installation-Guide-on-Ubuntu-16.04