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.

Saturday, June 22, 2013

Converting pdf figure into vectored eps figure!

I used linux "convert" command to convert pdf figures into eps files, but the output figure quality was very bad. Probably its not a vectored eps figure. Therefore, I searched more and found that eps figures created by pdftops are vectored.

To convert file.pdf into file.eps, run the following command in the terminal:

pdftops file.pdf file.eps 

Wednesday, June 12, 2013

How to create vectored eps file from LibreOffice Draw!

While writing papers in Latex, we need to have vectored eps files for good quality figures. LibreOffice Draw does not have any option to save as eps in the "save as" list. However, you can export a figure (or selection to avoid white space around the figure) as eps file.

Following are the steps:
  • Create a new figure or  open existing figure in LibreOffice Draw. You can even open Microsoft Office figures in LibreOffice Draw. 
  • Select the figure you want to save. Most of the times we want to save the whole figure, so we select all (ctrl+A). If you do not select the figure, LibreOffice Draw will store it as a page with unnecessary white space around the figure.
  • Click File->Export; a window will pop-up
  • At the bottom, from "File type", select eps format.
  • Check the "Selection" box.
  • Save at your desired location by clicking on save
*Note: For some figures the LibreOffice may have problem predicting size during exporting. It happened to me with tables without boundary. Try adding boundaries to avoid that. You can select line color white if you do not want the border to be visible.

Wednesday, January 2, 2013

Quick guide for basic usage of git (on bitbucket)

The procedure for routine work on git.

Step 1: Clone the repository on your local machine by running the command given on the bitbucket site.

  • git clone https://mksaini@bitbucket.org/mksaini/test.git


Step 2: At any time, before you start editing the code, update your local repo with latest commits with the following command:

  • git pull origin master


Step 3: Make your changes in the files and commit the changes

  • git commit -m "Committing changes" -a
Step 3.1: In case you have added a new file or folder to the repo, or you want to commit only particular file or folder, you need to specifically add that before running the above mentioned commit command (in that case, the commit command should be run without option "a"):
  • git add file/folder  


Step 4: Push the changes to the remote repo, i.e., reflect the commit in the remote repo:

  • git push -u origin master
The procedure for putting code in a new repo:

Step 1: Create a new repo on bitbucket (it is better to use the same name for the repo your local project folder)

Step 2: Go to you project folder and delete any previously present git files in there
  • rm -rf .git/
Step 3: Initialise git
  • git init
Step 4: Configure it for the remote repository. You can find the command to do that on bitbucket itself. To get that, select you repo, and then select "I am starting from scratch":
  • git remote add origin https://username@bitbucket.org/your_repo.git
Step 5: Add all
  • git add *
Step 6: Commit
  • git commit -m "My first commit"
Step 7: Push the changes to the remote repo (i.e. save on bitbucket)
  • git push -u origin master