Friday, August 13, 2010

Reading data from WebCam on Python using OpenCV

Hi Guys!!

This is a simple program (I mean it!! Its a 14 line python script) to read WebCam data live using Python and I have run the program on IDLE 2.6.

Btw, My other programs in OpenCV will be posted here.

I'll assume that you have OpenCV 2.0/2.1 installed on your Computer System. If you haven't, you may want to refer Installing OpenCV and then run this program.

The code:


Friday, August 6, 2010

Configure CDT and GTK+ Eclipse on Ubuntu

I have found lot of people searching on the internet for the right way to install GTK and configure it with Eclipse, but found no perfect solution posted on the web (except for discussion in forums). I'm writing this down so that you guys might not suffer as i did in configuring GTK and Eclipse.

  1. First i would ask you guys to install Eclipse from the official website: http://www.eclipse.org/downloads/  . I would ask you to install from the Tarball available on the web instead of sudo apt-get install. This is my personal preference. Extract it into a folder.
  2. Install CDT from help->install new softwares or download the respective CDT file and install it on Eclipse.
  3. Install GTK development libraries from package manager. Give the following command:

    sudo apt-get install gnome-core-devel build-essential
    libgtk2.0-dev libgtk2.0-doc dev-help
      (The good thing about Step 3 is that you don't have to
    configure GTK i.e, extract, compile, install, configure
    and make  programs detect the existing library)
  4. Open Eclipse. Open a new Eclipse Project by going to new->c++ project->Executable->Hello World C++ project and select Linux GCC.
  5. Open the source file and copy paste the sample, hello world code in the editor (available at http://library.gnome.org/devel/gtk-tutorial/stable/c39.html) and save it.
  6. Go to the project properties->C/C++ build->settings-> GCC C++ Compiler and in Command line pattern paste the following: ${COMMAND} `pkg-config --cflags --libs gtk+-2.0` ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}   all we are doing is adding `pkg-config --cflags --libs gtk+-2.0` to the existing command line pattern. We are adding this line so that while compiling it would find the libraries/headers.
  7. Now, do the above for GCC C++ Linker in properties->C/C++ build->settings-> GCC C++ Linker.
  8. Click on OK, go to Project->build project and it will build it successfully. Now, you can run your project.
Basically we are telling the compiler to add `pkg-config --cflags --libs gtk+-2.0` while compiling.

For compilation in Terminal, we can use the following:
g++ `pkg-config --cflags gtk+-2.0`  `pkg-config --libs gtk+-2.0` test.cpp -o test

Happy C++ programming on Eclipse.

Cheers,
Rahul Kavi.