Monday, September 26, 2011

OpenCV 2.3.1 on Ubuntu 10.10 or later

*Update: For OpenCV 2.4 on Ubuntu 12.04 see my latest post.

This post will guide you on how to compile and run OpenCV 2.3.1 on Ubuntu 10.10 or later.

First, install all prerequisites:
sudo apt-get install build-essential checkinstall git cmake ffmpeg 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 libtbb-dev libv4l-dev libopenexr-dev libunicap2-dev libavformat-dev libswscale-dev libdc1394-22-dev 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 python-numpy
This is not a minimal set of libraries, but it's a collection that will give you most of the functionality. For example, if you are sure that you will never need to use a firewire camera, you can ignore libdc1394-22-dev. But if you actually need to use this feature you will have to recompile OpenCV. Also, if you need CUDA support, follow the instructions in this post before continuing here.

Download OpenCV:
Extract and create a build directory:
tar -xvf OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1/
mkdir build
cd build
Now run cmake:
At this point check the output of cmake to make sure that all the features you are going to need are supported. If not you will have to install the corresponding libraries and run cmake again. Compile:
If everything went well you can go ahead and install:
sudo make install
Finally, add the following lines in your .bashrc:
# OpenCV stuff
To test that everything works, let's run the face detection demo. Go to the bin directory:
cd bin
And run:
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="../../data/haarcascades/haarcascade_eye.xml" --scale=1.3 ../../samples/c/lena.jpg
You should see something like this:

How to install CUDA 4.0 on Ubuntu 10.10 or later

First, you need to install the NVIDIA development drivers. Download the current version (270.41.19) here.
To install the dev drivers, reboot and go into recovery mode. Select the "Drop to root shell prompt" option. Now type:
sudo telinit 3
Login again using your username, then cd to the directory where you downloaded the drivers (e.g. ~/Downloads):
cd ~/Downloads
chmod u+x
sudo ./
Follow the instructions on the screen. Make sure you write to your xorg.conf file. When done reboot:
sudo reboot
Download the CUDA Toolkit from this page (Linux -> CUDA Toolkit for Ubuntu Linux 10.10).
cd ~/Downloads
chmod u+x
sudo ./
Finally, download the GPU Computing SDK from the above website.
cd ~/Downloads
chmod u+x gpucomputingsdk_4.0.17_linux
Add the these lines at the end of your ~/.profile (if your OS is 32-bit, remove the lib64 entry):
#CUDA stuff
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Now you just need to compile the samples. Assuming you installed the SDK in your home directory:
cd ~/NVIDIA_GPU_Computing_SDK
You can now run one of the demos, e.g. the particle demo
and you should see something like this:

Thursday, June 2, 2011

How to add users on Ubuntu

First, add the new user:
sudo useradd -c “John Smith” -m -s “/bin/bash” jsmith
and then create a password for the new user:
sudo passwd jsmith
The -c options lets you give a full name for the user, -m option creates a home folder, -s specifies the default shell.

Install Ubuntu Tweak on Ubuntu 10.10

Open a terminal and type:
sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak

Saturday, May 28, 2011

Install and Configure Tomcat6 on Ubuntu Linux

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.

The Java Servlet and JavaServer Pages specifications are developed under the Java Community Process.

Part 1
First, install tomcat6:
sudo apt-get install tomcat6 tomcat6-docs tomcat6-examples tomcat6-admin

Then configure a user to be manager and admin by adding the following lines
  <role rolename="admin"/>
  <role rolename="manager"/>
  <user username="YOURUSERNAME" password="YOURPASSWORD" roles="admin,manager"/>
in your /var/lib/tomcat6/conf/tomcat-users.xml. Make sure you put it between the <tomcat-users> and </tomcat-users> tags and don't forget to replace YOURUSERNAME with your actual username.
Now go to a browser and hit:
and you should see the welcome page.

Part 2
To restart tomcat you just need to say:
sudo /etc/init.d/tomcat6 restart
or if you want to start/stop/get status you just replace restart with start/stop/status.
To make this easier go to a terminal and type:
gedit tomcat
then add the following lines of text:

/etc/init.d/tomcat6 $1
then save and close and type:
chmod u+x tomcat
sudo mv tomcat /usr/local/bin
so if you want to stop tomcat you can now say:
sudo tomcat stop
Let's add auto-completion to our new command now. Open a terminal and type:
gedit tomcat
then copy paste the following
    local cur prev opts
    opts="start stop restart status"

    if [[ ${cur} == * ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
complete -F _tomcat tomcat
save and close gedit. Now type:
sudo mv tomcat /etc/bash_completion.d
You need to restart for this to take effect, but if you want to test it right away type:
. /etc/bash_completion.d/tomcat
Then as an example, type:
sudo tomcat re
and hit tab a couple of times. It should complete the word restart for you since it's the only valid option that begins with "re".

Thursday, May 19, 2011

Install Sun Java JDK in Ubuntu 10.10

To install Sun's Java 6 JDK on Ubuntu 10.10, add the Sun Java6 Community PPA and install:
sudo add-apt-repository ppa:sun-java-community-team/sun-java6
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin
sudo update-java-alternatives -s java-6-sun

Thursday, April 7, 2011

GRUB 2 Splash Images on Ubuntu

Here is how you can get a nice background image for GRUB boot menu.
First, install the "grub2-splashimages" package:
sudo apt-get install grub2-splashimages
Then edit /etc/default/grub and add the following line
Also, make sure that GRUB is loaded in the same resolution as the image
...and that's it. Update GRUB
sudo update-grub
and restart to see the results.

Wednesday, April 6, 2011

How to delete all .svn directories

If you are using subversion, at some point you probably tried to take some folders from one repository and try to commit then to another. Since each folder has a hidden .svn folder, subversion will complain that "they are already under version control". Here is how to recursively delete all .svn folders:

find . -name ".svn" -type d -exec rm -rf {} \; -prune -print

Friday, February 25, 2011

Copy Paste between Emacs and other applications

If you are using GNU Emacs in an X-windows environment like Gnome, you would have noticed that sometimes copy-pasting from Emacs to other applications or vice versa does not work.
To fix this, edit your .emacs file (located in your home folder) and add the following lines:
;; Send primary selection to clipboard so copy-paste works with other X-applications
(global-set-key "\C-w" 'clipboard-kill-region)
(global-set-key "\M-w" 'clipboard-kill-ring-save)
(global-set-key "\C-y" 'clipboard-yank)

OpenCV 2.2 on Ubuntu 10.10

*Update: For OpenCV 2.4 on Ubuntu 12.04 see my latest post.

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. It is released under a BSD license, it is free for both academic and commercial use. It has C++, C, Python and soon Java interfaces running on Windows, Linux, Android and Mac.

This is how to build and install OpenCV 2.2 on Ubuntu 10.10.

First, install the dependencies from the repositories:
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
Download the source code:
Extract, create the build directory:
tar xfv OpenCV-2.2.0.tar.bz2
rm OpenCV-2.2.0.tar.bz2
cd OpenCV-2.2.0
Configure, make and install:
cmake ..
sudo make install
To configure the library, edit the following file (might be empty):
sudo gedit /etc/
and add the line
Then run:
sudo ldconfig
Finally, edit the file:
sudo gedit /etc/bash.bashrc
and add the following lines at the end:
Most of the above was find here.

Older versions? Take a look at the following links:

OpenCV 2.1 on Ubuntu 10.04 (pretty much the same as above, but with TBB)
OpenCV 2.0 on Ubuntu 9.10

For OpenCV 2.3.1 see this post.

Saturday, February 19, 2011

Completely Disable Touchpad in Ubuntu

To temporarily disable the touchpad while typing just go to
System > Preferences > Touchpad
and check
Disable touchpad while typing
but if you want to completely disable it, you can do the following
In a terminal type:
xinput list | grep -i touchpad
to determine the device ID (in my case, 14). Then disable by typing:
xinput set-prop 14 "Device Enabled" 0
To enable it, type:
xinput set-prop 14 "Device Enabled" 1

From the Ubuntu Documentation: Synaptics Touchpad

Tuesday, February 15, 2011

Ogre3D Applications and Emacs

This is the first application of the Ogre3D tutorial, set up for compiling by calling
make -k
from Emacs. This is useful when you have a shortcut for M-x compile say, F1, so you want to be able to call make from the directory where all your source files are located. The Makefile in the root directory just removes old cmake files, then runs cmake inside build directory and creates the Makefile to build the project. Then builds and executes.

  • Cmake output is redirected to the file /build/cmake.output
  • The executable (OgreApp) is located in build/dist/build
  • The execution log is in build/dist/bin/OgreApp.log
Now you can edit the source files of your Ogre3D application, then hit F1 (or whatever key you've assigned compile to) and build/execute by just pressing one key.

You can download all files from here.

Friday, January 28, 2011

Command Line Shortcuts

I was reading this post today on how to become a command line ninja and here is some interesting stuff I learned:
  • Ctrl+U: This clears the entire line so you can type in a completely new command.
  • Ctrl+K: This deletes the line from the position of the cursor to the end of the line.
  • Ctrl+W: This deletes the word before the cursor only.
  • Ctrl+R: This lets you search your command history for something specific. For example, if you wanted to search for the recent commands that included nano, you would hit Ctrl+R and type nano. It would show your most recent  command, and you could use the up and down arrows to cycle through your history of commands using nano in them.