Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wandering007/b5aee2fd2e54b832c3b5b978ed7ec75b to your computer and use it in GitHub Desktop.
Save wandering007/b5aee2fd2e54b832c3b5b978ed7ec75b to your computer and use it in GitHub Desktop.
A simple way to install FFmpeg 2.8.6 and Opencv 2.4.11 in Ubuntu 14.04
1. install FFmpeg 2.8.6
Following the installation guide here: http://www.linuxfromscratch.org/blfs/view/svn/multimedia/ffmpeg.html
First download all the dependences and install them following the guides on the website blindly.
Optional dependencies and installation can be ignored.
When the preparation is done, just install ffmpeg blindly...Very easy!
2. install opencv 2.4.11
Download the souce file from https://github.com/Itseez/opencv/archive/2.4.11.tar.gz
tar -xvf opencv-2.4.11.tar.gz
Install the dependencies:
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev qt5-default
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
Since FFmpeg already includes libavcodec-dev libavformat-dev libswscale-dev, you don't have to install them (better not try to :-) ).
cd opencv-2.4.11/
mkdir release
cd release/
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 BUILD_FAT_JAVA_LIB=ON -D INSTALL_TO_MANGLED_PATHS=ON -D INSTALL_CREATE_DISTRIB=ON -D INSTALL_TESTS=ON -D ENABLE_FAST_MATH=ON \
-D WITH_IMAGEIO=ON -D BUILD_SHARED_LIBS=ON -D WITH_GSTREAMER=ON -D CUDA_GENERATION=Kepler ..
# attention about CUDA_GENERATION if you use cuda, get your gpu architecture, example here is Kepler.
# Some says set it to Auto will be fine. Sorry, I haven't try it.
# If you don't use gpu, you should remove that option and google some solutions since using gpu is part of opencv design.
# And -D BUILD_SHARED_LIBS=ON ensures that you can get dynamic lib, namely, .so files rather than .a files in /usr/local/lib/.
make -jN # N is the threads you use, not exceeding the number of cpu cores in your machine.
sudo make install -jN # N is explained as above
# if needed
sudo ln -s /usr/local/include/opencv-2.4.11/opencv /usr/local/include/opencv
sudo ln -s /usr/local/include/opencv-2.4.11/opencv2 /usr/local/include/opencv2
How to use python to import opencv?
python
>>>import cv2
if you get this kind of error: "ImportError: No module named cv2"
input the following codes before "import cv2"
>>>import sys
>>>sys.path.append('/usr/local/lib/python2.7/site-packages') or '/usr/local/python/2.7/'
To skip these two line codes, try adding the following line in ~/.bashrc
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH #or /usr/local/python/2.7/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment