Tuesday, September 29, 2009

Eclipse - OpenCV Project Setup

After you install OpenCV you will most likely want to use a programming IDE to write your code. In this case I am assuming you have chosen the Eclipse C++ IDE. To install this go here to download and untar the program where you will want it to reside on your machine.  Then run the program (no install necessary... it's written in java).

If you have installed the OpenCV library on your machine to /usr/local then you can follow this setup. Otherwise you will have to change how you link to OpenCV appropriately.  This section also relates to the setup of gtkmm and fftw.  If you do not want to use them, remove their sections.

1) Right click on your project and go to Properties
2) Go to the C/C++ Build section and then Settings
3) Under GCC C++ Compiler,  click on Directories
4) Add the following paths under Include Paths

/usr/local/include/opencv
/usr/lib/gtkmm-2.4
/usr/include/gtkmm-2.4


5) Under GCC C++ Compiler,  click on Optimization
6) Add the following under Other optimization flags

-ggdb `pkg-config opencv --cflags --libs` `pkg-config gtkmm-2.4 --cflags --libs`


7) Under GCC C++ Linker,  click on Libraries
8) Add the following under Libraries

cv
gtkmm-2.4
highgui
fftw3
9) Add the following under Library search path


/usr/local/lib
/usr/lib

Thursday, September 24, 2009

Neural Networks - Perceptron Character Recognition

A couple of years ago I took a really fun and challenging class called Introduction to Neural Networks.  We discussed the theory and applications of neural networks, including single- and multi-layer feedforward and recurrent networks, supervised and unsupervised learning, etc.

If you are unfamiliar with Neural Networks, they are methods that attempt to mimic the human brain (hence neural) by utilizing the basic fundamental building block of a neuron.  Neural Networks provide the ability to learn and make decisions based on various ideas related to increasing or decreasing the connections between neurons.

For a great introduction please see Jon Carrier's Neurocomputing Presentation

In this class I did a presentation on the ability of single perceptrons to perform character recognition.

Here is a link to my professors blog that describes our classes presentations: eceblogger

Here is a link to my presentation: Google Doc Link... Well I was going to post it, but I do not have it on hand just yet.  Will post once I get to it.

Some Interesting Bash Functions

In Linux there is a type of scripting that can be done in the Bash shell.  This is a very powerful feature of Linux, as Bash offers many advanced features.  This blog will show some of the features I have learned.  I will not attempt to cover a tutorial but rather varying functions that I have found useful.

IFS
   One of the interesting things that I have learned is the usage of IFS.  According to wikipedia it stands for Internal Field Separator.  What it does is allow you to define what Bash defines as a separator.  Bash defaults to space as the separator, therefore functions that utilize IFS will separate items based on spaces.

  While scripting you might want to change this.  Maybe a comma or a new line will be what is wanted.  Here is an example that sets the value to a new line and then back to the default.


#set IFS to be a new line
IFS="
"
#set IFS to be a space
IFS=" " 

Checking Arguments
  When you are implementing a bash script you can pass in arguments to the program.  Each argument is listed as $(value) where value ranges from 0 on up.  $0 is your program, $1 is the first passed in argument, etc.

Now what we want to do is check how many the user input.  Maybe we only want 2 values to be input, so we should check that.  Here is an example that checks for 2 inputs.


if [ $# -ne 2 ]; then
  echo "You did not input 2 arguments, try again!"
  exit
fi

Iterate Through all Files in CWD
  Sometimes it is necessary to iterate through all files in a certain directory.  There are a few ways to do this, but if you are dealing with files that may have spaces in them, the best way is the following.


for file in `ls -A $src`; do 
  sourceFile="$src/$file"
  # Now do what you want it to do with each source file
done


* Note: In the above example you will note $src, this is the full length path where you are searching files.  This can be a hard coded variable or possibly an argument to your function.

* Note: Whenever you reference sourceFile make sure to use quotes

Checking for Certain Things
  When you are coding you might want to check what something is.  Here are a few ways to check.

Checking that a directory exists

if [ ! -d "$dir" ]; then
  #do something since the directory does not exist
fi

Checking for a regular file

if [ -f "$file" ]; then
  #do something since it is a normal file
fi

Checking if file1 is newer than file2

if [ "$file1" -nt "$file2" ]; then
  # file1 is newer, so do something here
fi

Tuesday, September 15, 2009

Audio Watermarking

While working towards my Master's thesis I took an Advanced Topics class titled Speech Processing. In this class we covered the basics of processing speech data (not specifically speech recognition, but all encompassing). Topics such as the anatomy of speech production, speech synthesis, voice estimation and specific applications through student presentations. My presentation was on Audio Watermarking.

I found a recent paper on the subject and attempted to recreate what the authors had implemented. I implemented their algorithm in Matlab. Unfortunately it did not work as well as theirs, but I was lucky enough to be chosen as the best presentation by the class.

To view my presentation go here: Google Doc Link

For images of my presentation as well as other students please visit my professors eceblogger site.

Just for fun, here is an image of the matlab gui I created for this project.

Wednesday, August 26, 2009

Ubuntu OpenCV FFMPEG error

If you are in Ubuntu 9.04 and attempting to write a video using OpenCV you may encounter an error such as:

OpenCV Error: Bad argument (codec not found) in CvVideoWriter_FFMPEG::open

The only solution that I have found is to install the following
sudo apt-get install libavcodec-unstripped-52

It seems to remove a bunch of packages but everything I do (reading/writing videos) seems to be working. So proceed with caution on installing this, but it may fix what ails you.

Working with gtkmm - A basic intro

I am not attempting to know everything about gtkmm or post an exhaustive tutorial on it. However if you would like to create a basic GUI in a relatively short period of time then you have come to the right place.

Here is a link to a more exhaustive tutorial (where I learned myself):Programming with gtkmm

Also visit this link which has detailed information on each class/namespace/file:
gtkmm 2.4 Documentation

Quick Introduction:

Abstract:
This tutorial covers how to create a GUI including one button arranged within a single frame. In another post I will eventually cover the basics of how to create a "more" section (i.e. hidden widgets). This is a very basic GUI that simply allows you to run commands depending on the callback of the button.

Idea:
The basic idea of gtkmm (GTK in general) is to create a gui where all elements are relative in position and size (for the most part). Each element is considered a widget and the things that hold it, containers. Elements are typically considered children, and containers parent(s).

Main.h
Add:
#include 
#include "gui.h"


Main.cpp
Add:
Gtk::Main kit(argc,argv);
gui gui;
Gtk::Main::run(gui);


gui.h
Add:
class gui : public Gtk::Window
{
public:
gui();
virtual ~gui();

protected:
//Signal handlers:
virtual void on_button_clicked();

//WINDOW - Child widgets
Gtk::Frame window_frame;
Gtk::VBox window_box;
Gtk::Button window_button,

gui.cpp
Add:
// Sets the Window Title
set_title("Window Title");

// Sets the border width of the window
set_border_width(10);

// Add the box to the window (the window can contain one widget/container)
add(window_box);

// Add the frame to the box (boxes can contain multiple widgets/containers)
window_box.pack_start(window_frame);

// Label the frame
window_frame.set_label("Main");

// Add a button to the frame (frames can contain one widget/container)
window_frame.add(button);

// This is how you do a call back (to a function where you define whatever you want)
button.signal_clicked().connect(sigc::mem_fun(*this,
&gui::on_button_clicked));


That's it. Just define your on_button_clicked() function and you are all set to make a simple GUI.

How to post code on your blog

I was unaware of how to do this and did some searching online. There are many ways of doing it. The following blog has a great way to do it and the directions are very clear and to the point.

Vivian's Tech Blog - How to post source code in blogspot.com