-
installing FFMPEG dependencies
sudo apt-get install build-essential checkinstall libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev libsdl1.2-dev libvpx-dev -
Installing Gstreamer
sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good
有人说还有安装 gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg, 但是,在ubuntu16.04上,没有这三个库,不安装这三个库,也可以成功
2。 Installing libgtk2
sudo apt-get install libgtk2.0-0 libgtk2.0-dev
安装完成后,提示需要 运行sudo apt autoremove, 千万不能运行,否则,会删掉cuda, boost相关的库
3。 Installing libjpeg
sudo apt-get install libjpeg8 libjpeg8-dev
4。 Compile required libraries
Create a folder with the source code of all required packages:
mkdir ~/source
mkdir ~/source/v4l
mkdir ~/source/ffmpeg
-
Compile X264
https://www.videolan.org/developers/x264.html 下载: git clone http://git.videolan.org/git/x264.git
./configure --disable-asm
make
sudo make install- Compile ffmpeg
cd ..
https://www.ffmpeg.org/download.html 下载: git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ~/source/ffmpeg
./configure --enable-gpl --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libxvid --enable-nonfree --enable-version3 --enable-shared --enable-libvpx --enable-pic
make -j4
sudo make install
- Compile ffmpeg
-
Compile v4l
下载,解压
cd ~/source/v4l
https://www.linuxtv.org/downloads/v4l-utils/
找最新版本下载
configure
make
sudo make install
最后从github上下载opencv 和opencv-contrib:
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
通过cmake-gui配置、编译和安装
在配置cmake时注意:
OPENCV_EXTRA_MODULES_PATH ->opencv_contrib-master/modules
PYTHON2_EXECUTABLE--->venv/py27/bin/python2.7
PYTHON2_INCLUDE_DIR--->venv/py27/include/python2.7
PYTHON2_LIBRARY ---->/usr/lib/x86_64-linux-gnu/libpython2.7.so
PYTHON2_NUMPY_INCLUDE_DIRS-->venv/py27/lib/python2.7/site-packages/numpy/core/include
PYTHON2_PACKAGES_PATH--->lib/python2.7/dist-packages
PYTHON3_EXECUTABLE--->venv/py36/bin/python3.6
PYTHON3_INCLUDE_DIR--->venv/py36/include/python3.6m
PYTHON3_LIBRARY--->/usr/lib/x86_64-linux-gnu/libpython3.6m.so
PYTHON3_NUMPY_INCLUDE_DIRS--->venv/py36/lib/python3.6/site-packages/numpy/core/include
PYTHON3_PACKAGES_PATH--->lib/python3.6/dist-packages
编译和安装成功后:
cd /usr/local/lib/python2.7/dist-packages
sudo chmod +x ./cv2.so
cp ./cv2.so ~/venv/py27/lib/python2.7/site-packages/
cd /usr/local/lib/python3.6/dist-packages
sudo mv ./cv2.cpython-36m-x86_64-linux-gnu.so ./cv2.so
sudo chmod +x ./cv2.so
cp ./cv2.so ~/venv/py36/lib/python3.6/site-packages/
测试:
进入python虚拟环境,启动python
import cv2
网友评论