Monday, November 23, 2009

Kalman Filtering Application for Foggy Images

A couple of years ago I took an Estimation and Filtering class. We covered many different topics, but one of the main ones was Kalman Filtering. This is a very popular type of filtering and estimating that attempts to use past measurement(s) (noisy) and estimate the true current value(s) (with error minimized). Some assumptions are made with the type of noise that we are dealing with. Try this page or this page for some better descriptions of Kalman Filtering and the algorithm.

In this class we had to find an application and discuss it.  Here is my presentation on the paper titled:    A KALMAN FILTER BASED RESTORATION METHOD FOR IN-VEHICLE CAMERA IMAGES IN FOGGY CONDITIONS

Paper Link

Presentation Link

Wednesday, October 28, 2009

Gnuplot - Simple Tutorial

There are a ton of tutorials on how to use gnuplot, but most can be convoluted. Here is a simple example/tutorial for gnuplot.

1. Put data in a file (e.g. plot1.dat).  X-axis data followed by a space and Y-axis data

1 23.8
2 23.8
3 23.8
4 23.8
5 23.75
6 23.75
6.5 24.15
6.75 24.45
7 24.95
7.25 25.15
7.5 25.30
7.75 25.40
9 25.70
10 25.83
11 25.88
12 25.89
13 25.90
14 25.90

2. Put the setup commands in another file (e.g. plot1.setup)

# Basics
unset log
unset label
unset arrow
set xtic auto 
set ytic auto 
set autoscale

# Title Information
set title "Temperature vs. Time - Trial 1"
set xlabel "Time (min)"
set ylabel "Temperature (celsius)"

# Initial Point (1,23.80)
set label "i" at 2,24.8 font "Arial,25" offset 1
set arrow from 2,24.80 to 1,23.80

# Final Point (14,25.90)
set label "f" at 13,24.90 font "Arial,25" offset 1
set arrow from 13,24.90 to 14,25.90

# Time fired (6,23.75)
set label "a" at 6,24.75 font "Arial,25" offset 1
set arrow from 6,24.75 to 6,23.75

# Temp reaches 60% (7.1,25.04)
set label "b" at 8.1,25.04 font "Arial,25" offset 1
set arrow from 8.1,25.04 to 7.1,25.04

# Max Temp (13,25.90)
set label "c" at 12,24.90 font "Arial,25" offset 1
set arrow from 12,24.90 to 13,25.90

# Make the plot
plot "plot1.dat" with linespoints

3. Run the following command
   a. gnuplot -persist -raise plot1.setup

Thursday, October 15, 2009

C++ number precision

Today I learned a very useful feature that C++ has.  It is the precision of numbers when using streams. Below I will show how the .precision function is important if you want precision when displaying numbers to the screen using the cout function or when writing numbers to a file using ofstream.  Undoubtedly there are other ways to use it, but I am more concerned with those two functions.

COUT
The below code will produce an output that is the full 10 digits in length

double digit = 5.000000001
cout.precision(10);
cout << digit << endl;
visit here for a more in depth explanation/example

OFSTREAM 

The below code will save your value in 10 digit format to a file (appending it to the end)
// Make a value to write to a file called file.txt
double value = 15.12345678;

// Create and open a stream
ofstream myFileWrite; 
myFileWrite.open("file.txt",ios::app); // append to the end of the file

// Make sure we opened it right
if (!myFileWrite.is_open())
   return -1;


// Define the precision to write at 
myFileWrite.precision(10);

// Write the value to the file at the end of the file 
myFileWrite << value << endl;

// Close the file
myFileWrite.close();

Tuesday, October 6, 2009

Eclipse - Go to function

Following in the foot steps of Jon's blog on a very cool Eclipse function (Eclipse C/C++ IDE File/Folder Restore), here is another very useful function of Eclipse.

This function allows you to go to a variable, function, etc. from where you are calling it.  The variable/function that you are interested in is linked to another part of your code and Eclipse of course knows this (assuming you have completed a build).  So how do you do it?

Hold down the Ctrl button and click on the variable/function as if it were a regular link.

Friday, October 2, 2009

Senior Year Project - Robotics


At the University of New Hampshire Electrical Engineering Department there is a requirement to take a final project class for your entire last year. Students from EE and ME combine together and choose projects that they are interested in. Teams then complete a full development cycle on the project they choose. During the class we did such things as team organization, budget creation, criticality analyses, bill of materials, Gantt charts, weekly reports, complete testing for design verification, project design, hands-on creation of project, coding, engineering, and more! The project was very detailed and ended with a final product, a final report over 70 pages in length and a presentation at UNH's Interdisciplinary Science & Engineering Symposium (click here for the webpage).  Also visit the link for a video of the robot in action.  And you can see that we won "Best Project Presentation" for 2007.

(The robot image above is property of my buddy Jeff Nichols who was our team leader and made this for our team)

So what did my team do? We developed an Autonomous Fire Fighting Robot and entered it into the Trinity College Competition. My group, Johnny 5 Associates, Inc., had 5 engineers. We had 2 Software Engineers, 2 Electrical Engineers and a Mechanical Engineer. We designed a robot that had a Motorola Microprocessor, stepper motors, rechargeable batteries, CO2 extinguisher, horn detector, Hamamatsu flame detector, infrared phototransistors, sonar, and white-line detectors.




My main part of the project was sensor research/integration for location information, object detection, horn detection and cabling.

Location Information & Object Detection

In order to know where the robot is and where it should go I found multiple sensors that would follow along with the specifications set forth by Trinity College.  I decided to utilize 2 infrared "white-line" sensors, 4 sonar sensors and dead reckoning.  I looked at other sensors such as accelerometer and compass sensors, but decided against them for cost and other reasons.  The compass for example would not be the best choice because there can be metallic objects in the maze that could mess with the sensor.

Infrared "white-line" sensors
Each room in the maze had a white line across it.  We decided to use this line as a way to reorient the robot as it enters each room (thus decreasing error).  So as the robot approached the line, it would sense the line with one sensor and rotate the opposite wheel until the robot was square with the line.

Sonar sensors
To avoid objects that may be in the maze and to measure distances to the nearest walls we utilized sonar.  Infrared would have worked, but there is the possibility that mirrors may exist in the maze.  The sonar worked great most of the time, but weird readings would occur sometimes.

Dead Reckoning
A great method is one where you count the turns of your wheels.  In this case if you have a stepper motor, you can pulse the motors and count how many pulses you send.  Thus you can get a distance measure.  The problem with this is that you accumulate error over time.  In order to fix this error we would take measurements with the sonar at certain points to fix the error.

Horn Detection

One of the best parts of this project for me was the creation of a horn and a detector.  This was part of the rules as an added bonus.  The idea being that your  fire alarm goes off and the robot begins.  So the rules stated that your detector must be between 3 and 4 kHz and that you must provide a transmitter that a judge, or the user, can start the robot with.

I implemented a frequency transmitter using a 555 timer and a gain circuit that drives a small speaker.


I also implemented a frequency detector... Unfortunately we purchased a  pre-made circuit that can detect a certain frequency range based on your pot. adjustment and then it activates a relay.  It is unfortunate because I found a chip that performs the same task and is easily created.  Either way I had to create a triple gain stage from a microphone and feed it into the relay circuit which when activated flips the voltage of a microcontroller input.

The system worked flawlessly and was an impressive way to start the robot.

Make sure to come back to my blog as I will eventually be describing more of the robot in greater detail (with more images).







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

Thursday, August 20, 2009

How to Create a GUI with C++ (Linux Edition)

There are 2 main options when creating a GUI in C++ while in Linux. The options are GTK+ or QT.

GTK+

If using GTK+ w/ C++ you will want to see this page.

Ubuntu Install Instructions:
  • sudo apt-get install libgtkmm-2.4-dev
Eclipse Setup Instructions:

Add this line to your code:
  • #include <gtkmm.h>
Add the following to your optimization settings for GCC C++ Compiler
  • `pkg-config gtkmm-2.4 --cflags --libs`
Add the following to your Directories settings for GCC C++ Compiler
  • /usr/lib/gtkmm-2.4
  • /usr/include/gtkmm-2.4
Add the following to your Libraries under GCC ++ Linker
  • Under Libraries (-l):
    gtkmm-2.4
Now if you follow the gtkmm website examples you should be able to run them in eclipse.

Thursday, August 13, 2009

How to download & compile the latest OpenCV

Once you have your environment set up you will be able to download and compile OpenCV to your Linux environment easily. Some Linux distributions are easier than other to setup. Sabayon is one such distro that comes with many of the necessary packages already installed.

Execute the following commands:
  1. mkdir opencv
  2. svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk opencv
  3. cd opencv/opencv
  4. mkdir release
  5. cd release
  6. sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ../
Now make sure everything worked and was found. If you get errors you need to fix them now or else you will have issues completing a successful install.

Execute the following:

  1. sudo make
  2. sudo make install

If everything goes as planned OpenCV should compile successfully (100% during the make). If not check your libraries and if all else fails try getting the code from the SVN again.

There it is, you have installed OpenCV from source!

Update #1:
   If you receive the error from cxcorr.hpp indicating that ptrdiff_t does not name a type, please add this line of code to cxcorr.hpp (as indicated by stackoverflow.com):

  1. #include <stddef.h>

Setting up Ubuntu for OpenCV

This article relates how to setup a fresh Ubuntu (9.04 - Jaunty Jackalope) so you can download the latest OpenCV from the repository and then compile it from scratch. Downloading and compiling will be a separate article.

First install some packages using the following commands:
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install mplayer
sudo apt-get install subversion
sudo apt-get install ffmpeg
sudo apt-get install swig
sudo apt-get install python-all
sudo apt-get install python-all-dev
Second install some libraries using the following commands:
sudo apt-get install libxine1
sudo apt-get install libfftw3-3
sudo apt-get install libfftw3-3-dev
sudo apt-get install libfftw3-dev
sudo apt-get install libvorbis-dev
sudo apt-get install libavcodec-dev
sudo apt-get install libavdevice-dev
sudo apt-get install libavfilter-dev
sudo apt-get install libavformat-dev
sudo apt-get install libavutil-dev
sudo apt-get install libmad0
sudo apt-get install libmad0-dev (maybe not necessary)
sudo apt-get install libpostproc-dev
sudo apt-get install libswscale-dev
sudo apt-get install libxine1-ffmpeg
sudo apt-get install libjasper-dev
sudo apt-get install libtiff4-dev
sudo apt-get install libv4l-dev
sudo apt-get install libslang2-dev
sudo apt-get install libxine-dev
sudo apt-get install libdc1394-22-dev
sudo apt-get install libgstreamer0.10-dev
sudo apt-get install libgtk2.0-dev
Now go into Add/Remove Programs
  1. Search for java runtime
  2. Install Sun Java 6 Runtime
*Note: You will want to select All available applications under Show:
Now install unicap

Follow the directions here, then run the following commands:
sudo apt-get install libunicap2
sudo apt-get install libunicap-dev
sudo apt-get install libucil2
sudo apt-get install libucil-dev
sudo apt-get install libunicapgtk2
sudo apt-get install libunicapgtk-dev

* You can also dowloand the tar.gz and compile and make that by hand

* If you are having trouble writing to files with OpenCV after you have installed all the above, please read this link for the fix.

Welcome

Welcome to the Reyco Technologies blog! I will be posting various articles that will first and foremost be related to my thesis and then various other techy articles when I learn/find something new.