Sunday, April 12, 2015

Ubuntu Matlab: Error using VideoFileReader/setup Could not open the specified file.

In order to read video file using vision.VideoFileReader object, you need to initialize it:

video_source = vision.VideoFileReader('test.avi')

Now, to access a (next) frame of the video, you need to run the following command:

frame  = step(videoSource);

If you are doing it for the first time after fresh Matlab installation, you will probably run into the following error:

Error using VideoFileReader/setup 
Could not open the specified file.

This happens because Matlab is unable to find the correct codec to decode the video file. To solve this problem, follow these steps:


  • Install ubuntu-restricted-extras
    • sudo apt-get install ubuntu-restricted-extras
  • Install Gstreamer
    • sudo add-apt-repository ppa:gstreamer-developers/ppa
    • sudo apt-get update
    • sudo apt-get install gstreamer0.10-tools gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad
  • Install gstreamer0.10-ffmpeg 
    • sudo add-apt-repository ppa:mc3man/trusty-media
    • sudo apt-get update 
    • sudo apt-get install gstreamer0.10-ffmpeg
Restart the Matlab and it should work just fine!

Enjoy!



Sunday, March 29, 2015

The curious writing style of Benjamin to manage the overall THEME of the paragraphs and paper!

It is very simple.

Instead of writing full text in the beginning itself, write 2-3 lines summarizing the message you want to convey by each paragraph.  While writing the full text, just expand these lines. Make sure that the content you add to each paragraph adheres to the final message of the paragraph.

To manage the theme of the whole paper, just write the messages of each paragraph and read them all together. You will get a clear idea of whether or not the paragraphs follow a single theme and story. 

Monday, August 19, 2013

How to remove white space from eps and pdf figures!

When we store figures as pdf, they are stored with high quality in a vector format.  But generally the whole page is stored, with lot of white space around the actual figure. There are two ways to remove this space.

1. Convert to eps and remove space from eps

Do NOT use GIMP autocrop feature for removing the space. GIMP converts the images into bitmaps (non-vectored) which is bad quality. 

Follow the steps below to create high quality eps figures and remove space:
  • pdftops file_with_space.pdf file_with_space.eps
  • cat file_with_space.eps | ps2eps > file_without_space.eps

2. Remove space directly from pdf

To do that, use the pearl script given at http://www.ctan.org/tex-archive/support/pdfcrop/. For instructions, read the README file.

Wednesday, July 31, 2013

latexdiff: Excellent tool to view modifications!

It is hard to specifically see the changes in two versions of a paper. It is even harder to spot those changes in the .tex files. To visualize the changes (or differences) between two latex version of a paper, we can use an excellent tool, latexdiff, freely available for linux. It can be installed with a simple command:
  • sudo apt-get install latexdiff 
The output file will have colors and annotations to mark the differences. The name of the output file is derived from the input filenames.

Difference of two local .tex files (latexdiff)

  • latexdiff --flatten --pdf old-file.tex new-file.tex > diffs.tex
(the –flatten argument makes latexdiff recursively operate on any included .tex files.)

Difference of SVN versions (latexdiff-vc)

  • Compare current working copy with earlier version
    • latexdiff-vc --pdf --flatten -r version file.tex > diffs.tex
  • Compare two versions
    • latexdiff-vc --pdf --flatten -r version1 -r version2 file.tex > diffs.tex

A guide to begin work at University of Ottawa

Important Formalities

  1. On the first day you arrive Ottawa, go to City Hall (City of Ottawa) and apply for SIN (Social Insurance Number) and OHIP (Ontario Health Insurance Plan).
    • For SIN, you only need your passport and work permit. Carry your job offer just in case.
    • For OHIP, you need to provide a proof of address. You can carry your lease agreement. 
  2. To be on campus, you need to have medical insurance. Your free insurance (OHIP) only starts after three month. Therefore, you need to apply for private insurance for these three months. You can do that at the HR office. It will cost you around C$171 for three months. Chose the option to pay from your salary.
  3. Come to the department and meet Prof. You need to sign a contract with Prof and submit a to the department office. After approval from the Director, you will get a copy of the contract.
  4. You need to take that copy to the FGPS for registration as postdoctoral researcher.

Other Logistics

Access Card

Go to the department and obtain forms to fill. You need your supervisor to sign those form. You also need to finish WHMIS test before you can get access card. 

Email ID

You will get it automatically after registration.

Staff Card

You will get staff card from HR office.

Thursday, June 27, 2013

Most Complete Guide For Installing, Compiling, and Running OpenCV on Ubuntu!

I went through many guides to install OpenCV on my Ubuntu machine, but most of them are incomplete. A complete installation of OpenCV, with working video encoding/decoding functionalities, requires support of ffmpeg and x264, which in turn depend on many other libraries. 

In this guide, we will first install x264 and ffmpeg, and eventually OpenCV. Finally we will see how to configure OpenCV and compile programs. Most of the information is found at the following three blogs: [1], [2], and [3].


1. Remove old ffmpeg and x264

  • sudo apt-get remove ffmpeg x264 libx264-dev libav-tools libvpx-dev

2. Install all dependencies for ffmpeg and x264

  • 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 pkg-config
  • Download and install yasm 1.2.0 from here
    • ./configure --prefix=/usr
    • make
    • sudo make install
Image I/O
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev
Video I/O
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
Python
sudo apt-get install python-dev python-numpy
Download and install libjpeg
sudo apt-get install libjpeg8 libjpeg8-dev
Other third-party libraries
sudo apt-get install libtbb-dev
GUI
sudo apt-get install libqt4-dev libgtk2.0-dev

3. Install x.264 and ffmpeg

In install x264 and ffmpeg, I mainly follow the guide given at [3]. Below are the main steps.

X264

Download and install latest x264 from videolan.org.
  • git clone --depth 1 git://git.videolan.org/x264
  • cd x264
  • ./configure --enable-static --enable-shared
  • make
  • sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes --fstrans=no --default

libvpx

  • git clone --depth 1 http://git.chromium.org/webm/libvpx.git
  • cd libvpx
  • ./configure --enable-shared
  • make
  • sudo checkinstall --pkgname=libvpx --pkgversion="1:$(date +%Y%m%d%H%M)-git" --backup=no \--deldoc=yes --fstrans=no --default
If you get some error like "relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC",  compile libvpx with  "fPIC" option. You can do it with the following modified configure command": 
CFLAGS=-fPIC ./configure --enable-shared


Install librtmp

apt-get install librtmp-dev

FFMPEG

Downlaod latest ffmpeg 1.2.1 from here. Go to the download folder and run the following commands:
  • tar -xvf ffmpeg-1.2.1.tar.bz2
  • cd ffmpeg-1.2.1/
  • ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb   --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis   --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab --enable-shared --enable-pic
  • make
  • sudo make install

4. Install OpenCV

Get a copy of the latest source code here for OpenCV 2.4.5. Open a terminal and go to the directory where you have downloaded the tar file, and run the following commands:
  • tar -xvf opencv-2.4.5.tar.gz
  • cd opencv-2.4.5/
  • mkdir build
  • cd build/
  • cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON -D CMAKE_INSTALL_PREFIX=/usr/local ..
  • make
  • sudo make install

5. Configure OpenCV

We need to tell linux where the shared libraries for OpenCV are located by entering the following shell command:
  • export LD_LIBRARY_PATH=/usr/local/lib

Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal.
Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text /usr/local/lib to the end of a file named/etc/ld.so.conf.d/opencv.conf. In the standard Ubuntu install, the opencv.conf file does not exist; you need to create it. Using vi, for example, enter the following commands:
  • sudo vi /etc/ld.so.conf.d/opencv.conf
  • G
  • o
  • /usr/local/lib
  • :wq!

After editing the opencv.conf file, enter the following command:
  • sudo ldconfig /etc/ld.so.conf

Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:
  • PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
  • export PKG_CONFIG_PATH

After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV:
  • g++ `pkg-config opencv --cflags` my_code.cpp  -o my_code `pkg-config opencv --libs` 

If you are using a Makefile, append CFLAGS and LDFLAGS as follows:
#Compiler flags
CFLAGS=-c `pkg-config opencv --cflags`
#Linker flags
LDFLAGS= `pkg-config opencv --libs`

Note: Sometimes Makefile does not include libraries if you put LDFLAGS in the middle of link command, i.e.
  • g++ $(OBJECTS) $(LDFLAGS) -o output
It is better to put $(LDFLAGS) at the end of the command after specifying output file, i.e. 
  • g++ $(OBJECTS) -o output $(LDFLAGS)

       

[1] http://karytech.blogspot.ca/2012/05/opencv-24-on-ubuntu-1204.html
[2] http://www.ozbotz.org/opencv-installation/\
[3] https://gist.github.com/faleev/3435377

How to connect to uOttawa network through vpnc on Ubuntu Linux!

Basic Setup

If you find is difficult to install standard university provided vpn software, you can use the vpn client that comes with Ubuntu, vpnc.  All you need is the information to create a configuration file. University provides a configuration file in a different format. We need to conver it in right format, copy at right place, and just run it.

Following are the steps to connect your Ubuntu linux machine to university vpn:
  1. Download the empl.pcf file from the following link: 
  2. Open the terminal and go to the folder where you downloaded empl.pcf and run the following command:
    • pcf2vpnc empl.pcf  empl.conf
  3. Copy the empl.conf file to /etc/vpnc/
    • sudo cp empl.conf>/etc/vpnc/
  4. Run vpnc with empl as argument
    • sudo vpnc empl
  5. Enter username (for employees its "E" followed by your employee number without the leading '100',e.g. E123456) and password (infoweb password).
  6. You can also hard code username and password in empl.conf file by uncommenting 
    • Xauth username
    • Xauth password
  7. To disconnect, run following command
    • sudo vpnc-disconnect

If some of the commands do not work on your computer, you may have to install new software. Find more information here

Advanced

Same procedure should work to connect to any private network. You just need the following information from the private network owner: 

IPSec gateway
IPSec ID
IPSec secret
IKE Authmode
Xauth username
Xauth password

Obtain this information and store in myvpn.conf; and follow the instructions above to run the vpn client.