Wednesday, November 30, 2011

Installing OpenCV 2.3.1 with FFmpeg on 64-bit Ubuntu

There are many good tutorials out there which describe the installation procedure of OpenCV with FFmpeg. However few of them are comprehensive and even fewer explain the proper setup procedure for a 64-bit machine. Below are the steps that I have been following while setting up OpenCV with FFmpeg on a couple of new 64-bit systems in our lab (with Ubuntu 11.10). OK, here we go:

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.

Thursday, August 25, 2011

How to display any X-windows app remotely?

1st Method:

For this, your ssh configuration needs to be set so that you forward X11 requests. This is very easy to do globally. On your local machine, open or create the file ~/.ssh/config and write the following at the top:

ForwardX11 yes

That will try to forward X11 requests no matter who you connect to. It sets the DISPLAY variable correctly and does all the hard work. Note that you should remove any DISPLAY variable in your .bashrc file on the remote server, because it might conflict with what SSH tries to do automatically.

You should now be able to run any GUI application remotely over ssh.

2nd Method:

SSH using the "-X" option. For example:

ssh -X user@machine

The 1st method is the best because it's a one time setting that has to be done.

Saturday, July 23, 2011

Youtube video to GIF

Here are the steps that I followed:

1. Download video from Youtube using Chrome's Youtube plugin. It will get downloaded in MP4 format.

2. Convert from MP4 format to MOV using the command (in a Linux/Mac terminal):

ffmpeg -i input.mp4 -f mov -vcodec copy -acodec copy output.mov

3. Import the MOV file in Adobe Photoshop using the "File -> Import -> Video Frames to Layers" option and select the section of the video that you want to convert to GIF.

4. Resize to desired size using "Image -> Image Size" option

5. Export as GIF using "File -> Save for Web and Devices" option. Select the required GIF settings and click "Save"

6. If you want to upload to the web: My favorite image sharing website www.imgur.com has 2 MB limit on GIF upload size. For GIFs greater than 2 MB, you can use www.min.us.

Wednesday, March 30, 2011

Kalman Filters

I found a very "friendly" introduction to Kalman Filters. Here it is:

Chapter 1 in Maybeck, Peter S. 1979. Stochastic Models, Estimation, and Control, Volume 1, Academic Press, Inc.

Here is the PDF:

http://www.cs.unc.edu/~welch/media/pdf/maybeck_ch1.pdf

Next, read this:

Sorenson, H. W. 1970. "Least-Squares estimation: from Gauss to Kalman," IEEE Spectrum, vol. 7, pp. 63-68, July 1970.

Here is the PDF:

http://www.cs.unc.edu/~welch/kalman/media/pdf/Sorenson1970.pdf

Monday, February 7, 2011

ROC Curves

Here is a nice tutorial on ROC curves:

http://gim.unmc.edu/dxtests/ROC1.htm

Thursday, January 6, 2011

Resizing and Scaling with ImageMagick

I found this awesome guide to resizing and rescaling using ImageMagick:

http://www.imagemagick.org/Usage/resize/

Bookmarking it here for future reference.