Create a directory where the installation files will be downloaded:
$ mkdir ~/Tools $ cd ~/Tools
Update your package index:
sudo apt-get update
Install the dependencies for x264 and FFmpeg:
$ sudo apt-get install build-essential checkinstall git cmake 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
Get 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
Get yasm:
$ sudo apt-get install yasm
Download x264 and install it:
$ git clone git://git.videolan.org/x264 $ cd x264 $ ./configure --enable-static --enable-shared $ make $ sudo make install $ cd ..
Get the libs necessary for FFmpeg installation:
$ sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev
Download FFmpeg and install it:
$ git clone --depth 1 git://git.videolan.org/ffmpeg $ cd ffmpeg $ ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \ --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 \ --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-shared $ make $ sudo make install $ cd ..
Install gtk:
$ sudo apt-get install libgtk2.0-0 libgtk2.0-dev
Install libjpeg:
$ sudo apt-get install libjpeg62 libjpeg62-dev
Install v4l:
Get the latest version of v4l from here. The version used in this installation is 0.8.5
$ wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-0.8.5.tar.bz2 $ tar -xvf v4l-utils-0.8.5.tar.bz2 $ cd v4l-utils-0.8.5 $ make $ sudo make install $ cd ..
Get the python libraries:
$ sudo apt-get install python-numpy python-sphinx python-dev
Finally install OpenCV:
Get the latest version from here. The version used in this installation is 2.3.1
$ wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2 $ tar -xvf OpenCV-2.3.1a.tar.bz2 $ cd OpenCV-2.3.1 $ mkdir Build $ cd Build $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. $ make $ sudo make install
If you want to see all the options while building OpenCV, use "ccmake .." instead of the above mentioned cmake command. Done! Hope that helped.
Hi Vinay, thanks for this useful guide.
ReplyDeleteCheers,
Camilo
Thanks!
Deletehey vinay..nice post..
ReplyDeletebut can u help me out in installing openCV 2.3.1..i would b using MS Visual Studio 2008 Express Edition
if u can...please mail me the steps..or any link wer i can find the steps to install..
my email address is: yashreads@yahoo.com
thanks.. :)
Sorry, I have no experience with Windows based installations.
DeleteI used this video.
Deletehttp://www.youtube.com/watch?v=kZvjTTK9zTw
This is an awesome post. Thank you so much. This works perfect!!!
ReplyDeleteinstalling opencv is not a joke at all if you don't know what to do. This post explains what and how to install very straight forward.
5 stars on this post!!!
Thanks :)
DeleteHi,
ReplyDeleteI have installed it following your instruction. Nevertheless, right now, my java program cannot recognize it. Do you know how to configure opencv libraries with my java program?? Thanks.
Sorry, I have no experience with OpenCV + Java. I have always only worked on OpenCV with C++.
DeleteThis comment has been removed by the author.
ReplyDeleteVery useful post Vinay. Thanks.
ReplyDelete-Ravi
I have ubuntu 10.10….
ReplyDeleteI want ffmpeg with Opencv2.3.1 support….
I did the installation many times before….with building ffmpeg manually as you said….
Its working fine also its showing me ffmpeg support ON at the time of configuring OpenCv 2.3.1…
But when I use CV_FOURCC(‘F’,'L’,'V’,’1′) to create .flv file through cvCreateVideoWriter I am getting this error [flv @ 0x9bf5000] Tag FLV1/0x31564c46 incompatible with output codec id ’22′….
Is their any thing wrong I had done while installation….
An easy way...
ReplyDeletehttps://launchpad.net/~gijzelaar/+archive/opencv2.3
Ffmpeg has to be version of 7.11 or earlier because OpenCV hasn't managed to keep up with the update of FFMPEG. If it's later than 7.11,then cap_ffmpeg_impl.cpp may give error while building at 33%.
ReplyDeleteMore over, if one wants include tbb and enable other options in cmake I think it's better to build by cmake from the cmake-gui rather than the terminal.
ReplyDeleteThat's true. I edited the post to mention this. Thanks for the comment.
DeleteMr. Vinay, will the steps be the same for 32bit linux?
ReplyDeleteNo. Some steps are different. There are several other excellent tutorials out there for a 32-bit build.
Delete+ BUILD_NEW_PYTHON_SUPPORT instead of BUILD_PYTHON_SUPPORT
ReplyDelete+ opencv 2.3.1 requires ffmpeg 0.8.x if you do it according to your guide you download 1.0
Thanks, I edited the post to reflect this.
DeleteIn case you want to make a package out of your OpenCV compilation (and maybe hand it to other ppl), replace sudo make install with this:
ReplyDeletesudo checkinstall --pkgname=opencv-svn --pkgversion="2:$(date +%Y%m%d%H%M)-opencv" --default --backup=no
Thanks for the info. I did not know about this.
DeleteHi Vinay...........Thanks for this nice and useful post.
ReplyDeleteI am getting error at 14% after using make command.
I dont know what is the problem.....
pls help ...
thanks
Avinash
As mentioned in one of the replies, the instructions download the latest version of FFmpeg which is not supported in OpenCV 2.3.1.
ReplyDeleteSOLUTION: Download FFmpeg 0.10 (from http://ffmpeg.org/releases/), untar it and continue from line 2 of the ffmpeg section (ignore the git-related line).
I'd add one more line to this instruction set as a sanity check. Run the OpenCV test suite: ./opencv_test_core (located in OpenCV-2.3.1/Build/bin)
About the FFmpeg support : following the instructions "git clone --depth 1 git://git.videolan.org/ffmpeg" generate an error when i build openCV. (about KGD post : the last version when i tried was the 0.10.3, so i guess 0.10 won't work either)
ReplyDeleteAn anonymous said "FFmpeg has to be version of 7.11 or earlier because OpenCV hasn't managed to keep up with the update of FFMPEG"
So i randomly tried with 0.6.5, then the build is ok but not the bin/opencv_test_xxx which failed on many different points, and so in my owns programs the VideoCapture failed at the opening.
Do you know a version of FFmpeg that work (for ubuntu 12.04 64b) ?
Thanks in advance.
I just installed it on 12.04 64bit with the provided instructions,
Deletejust before building and deploying OpenCV after the instruction above circa june1st2012, I also installed the openCL cuda libs and sdk from
http://developer.nvidia.com/cuda-downloads
currently 4.2,
and followed the instructions here: http://berenger.eu/blog/2011/11/25/gpu-install-cuda-opencl-on-ubuntu/
and installed tbb with
sudo apt-get install libtbb-dev
I used ccmake to set the cuda and tbb options on. I just tested facedetect and it works in real time (the moment a face in in view) I'm stoked.
Thanks so much for such an informative and well maintained site Vinay, you bring honor to the craft.
ReplyDeleteif you are using CUDA and nvidia current you need to create a link : su -c 'ln -s /usr/lib/nvidia-current/libnvcuvid.so /usr/lib/libnvcuvid.so && ln -s /usr/lib/nvidia-current/libnvcuvid.so.1 /usr/lib/libnvcuvid.so.1'
ReplyDeleteRegards
Haan..Finally stumbled upon it. FFMpeg is a Bitch!
ReplyDelete-Jigar
Hello Vinay
ReplyDeleteI hope that you help me. I try install OpenCV. However, when I install OpenCV I had this error:
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
Before I see your tutorial I tried with another intalling_OpenCV and I had the same error.
I don't know why?? I have ubuntu 14.10, Can it be the problem??
Great and I have a tremendous offer: How Much Is Home Renovation house renovation contractors near me
ReplyDelete