Project Log Entry 1

My final year team engineering project is computer vision based object tracking system. A camera will follow an object, trying to keep it at the center, as it moves it front of it. Primarily, our objective is to detect the object that is moving and then using a motorized platform, rotate the camera. First, we will do a side-wise panning platform, then up-down panning. If possible we will make a motorized object follower by integrating the whole system in a singular device. For that we are planning to use a Linux based ARM board (viz. BeagleBoard).

For computer vision we are using OpenCV. After testing multiple languages and computer vision libraries, it was apparent that OpenCV is the best library out there. Previously, JMyron and Blob Detection in Processing was used. Then now, it’s fully OpenCV. Primary prototyping will be done by Python. If possible we will migrate it to C for better performance.

The rotation platform and the PC will communicate with a Bluetooth Serial communication module, or cable serial. The motorized platform would have stepper motors, controlled with an AVR (presumably, ATmega8). AVR programming will be done with AVRGCC.

Currently our focus is on Computer Vision. Exploring capabilities of OpenCV. Our current plan is to use contour detection, then using the contour CG as our control point, we will rotate the camera. Assuming we will face problems with the control feedback to the rotor, we will have to explore control schemes. We might use predictive filtering techniques to predict control points and Kalman filtering as primary control point detection.

The camera being used is a Logitech C270 webcam.

Experiments with OpenCV yielded some results…

Canny edge detection

Contour detection

Haar-like object detection as face detection

Advertisements

Glow-in-the-dark

It’s quite simple. It uses an MSP430G series micro-controller and an LDR for detecting light intensity. The detection is translated into interrupts with the analog comparator in the MCU. The special point about this is that it consumes really low power, thanks to the low power MSP430 micro-controllers from TI. It’s running on two AA alkaline batteries for nearly a month with being always powered on standard day night cycles.

Heap Allocation Experiment

I did this experiment on July, 2008 and totally forgot about it. I was looking for some of my old experiments and found this. It’s quite a nice little experiment.

It’s about comparing C compilers. I simply made program allocate some memory space for a certain array and allocated some memory again and measured the difference in pointer values (the memory distance).

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define MAX 100

int main(int argc, char *argv[]){
    int i;
    FILE *output;
    output=fopen("results.txt","w");
    fprintf(output,"char array\n");
    for(i=1; i<=MAX; i++){
             char *array1=(char*)malloc(i * sizeof(char));
             char *array2=(char*)malloc(sizeof(char));
             fprintf(output,"The free space for %d length 'char' array is %ld\n",i,array2-array1);
             free(array1);
             free(array2);
    }
    return 0;
}

I modified the original program a little and compiled with various compilers and got the results. The results are stored in result.txt.

I tested it on three different compiler/OS combinations.

MinGW (gcc (GCC) 3.4.5 (mingw-vista special r3)) on Windows 7 64 bit/Core i3 370M:

char array
The free space for 1 length 'char' array is 7376
The free space for 2 length 'char' array is 7376
The free space for 3 length 'char' array is 7376
The free space for 4 length 'char' array is 7376
The free space for 5 length 'char' array is 7376
The free space for 6 length 'char' array is 7376
The free space for 7 length 'char' array is 7376
The free space for 8 length 'char' array is 7376
The free space for 9 length 'char' array is -7376
The free space for 10 length 'char' array is -7376
The free space for 11 length 'char' array is -7376
The free space for 12 length 'char' array is -7376
The free space for 13 length 'char' array is -7376
The free space for 14 length 'char' array is -7376
The free space for 15 length 'char' array is -7376
The free space for 16 length 'char' array is -7376
The free space for 17 length 'char' array is -7376
The free space for 18 length 'char' array is -7376
The free space for 19 length 'char' array is -7376
The free space for 20 length 'char' array is -7376
The free space for 21 length 'char' array is -7376
The free space for 22 length 'char' array is -7376
The free space for 23 length 'char' array is -7376
The free space for 24 length 'char' array is -7376
The free space for 25 length 'char' array is -7376
The free space for 26 length 'char' array is -7376
The free space for 27 length 'char' array is -7376
The free space for 28 length 'char' array is -7376
The free space for 29 length 'char' array is -7376
The free space for 30 length 'char' array is -7376
The free space for 31 length 'char' array is -7376
The free space for 32 length 'char' array is -7376
The free space for 33 length 'char' array is -7376
The free space for 34 length 'char' array is -7376
The free space for 35 length 'char' array is -7376
The free space for 36 length 'char' array is -7376
The free space for 37 length 'char' array is -7376
The free space for 38 length 'char' array is -7376
The free space for 39 length 'char' array is -7376
The free space for 40 length 'char' array is -7376
The free space for 41 length 'char' array is -7376
The free space for 42 length 'char' array is -7376
The free space for 43 length 'char' array is -7376
The free space for 44 length 'char' array is -7376
The free space for 45 length 'char' array is -7376
The free space for 46 length 'char' array is -7376
The free space for 47 length 'char' array is -7376
The free space for 48 length 'char' array is -7376
The free space for 49 length 'char' array is -7376
The free space for 50 length 'char' array is -7376
The free space for 51 length 'char' array is -7376
The free space for 52 length 'char' array is -7376
The free space for 53 length 'char' array is -7376
The free space for 54 length 'char' array is -7376
The free space for 55 length 'char' array is -7376
The free space for 56 length 'char' array is -7376
The free space for 57 length 'char' array is -7376
The free space for 58 length 'char' array is -7376
The free space for 59 length 'char' array is -7376
The free space for 60 length 'char' array is -7376
The free space for 61 length 'char' array is -7376
The free space for 62 length 'char' array is -7376
The free space for 63 length 'char' array is -7376
The free space for 64 length 'char' array is -7376
The free space for 65 length 'char' array is -7376
The free space for 66 length 'char' array is -7376
The free space for 67 length 'char' array is -7376
The free space for 68 length 'char' array is -7376
The free space for 69 length 'char' array is -7376
The free space for 70 length 'char' array is -7376
The free space for 71 length 'char' array is -7376
The free space for 72 length 'char' array is -7376
The free space for 73 length 'char' array is -7376
The free space for 74 length 'char' array is -7376
The free space for 75 length 'char' array is -7376
The free space for 76 length 'char' array is -7376
The free space for 77 length 'char' array is -7376
The free space for 78 length 'char' array is -7376
The free space for 79 length 'char' array is -7376
The free space for 80 length 'char' array is -7376
The free space for 81 length 'char' array is -7376
The free space for 82 length 'char' array is -7376
The free space for 83 length 'char' array is -7376
The free space for 84 length 'char' array is -7376
The free space for 85 length 'char' array is -7376
The free space for 86 length 'char' array is -7376
The free space for 87 length 'char' array is -7376
The free space for 88 length 'char' array is -7376
The free space for 89 length 'char' array is -7376
The free space for 90 length 'char' array is -7376
The free space for 91 length 'char' array is -7376
The free space for 92 length 'char' array is -7376
The free space for 93 length 'char' array is -7376
The free space for 94 length 'char' array is -7376
The free space for 95 length 'char' array is -7376
The free space for 96 length 'char' array is -7376
The free space for 97 length 'char' array is -7376
The free space for 98 length 'char' array is -7376
The free space for 99 length 'char' array is -7376
The free space for 100 length 'char' array is -7376

Visual C++ 2010 (Microsoft Visual Studio 2010 Version 10.0.30319.1 RTMRel Microsoft .NET Framework Version 4.0.30319 RTMRel) on Windows 7 64 bit/Core i3 370M:

char array
The free space for 1 length 'char' array is 64
The free space for 2 length 'char' array is 64
The free space for 3 length 'char' array is 64
The free space for 4 length 'char' array is 64
The free space for 5 length 'char' array is 72
The free space for 6 length 'char' array is 72
The free space for 7 length 'char' array is 72
The free space for 8 length 'char' array is 72
The free space for 9 length 'char' array is 72
The free space for 10 length 'char' array is 72
The free space for 11 length 'char' array is 72
The free space for 12 length 'char' array is 72
The free space for 13 length 'char' array is 80
The free space for 14 length 'char' array is 80
The free space for 15 length 'char' array is 80
The free space for 16 length 'char' array is 80
The free space for 17 length 'char' array is 80
The free space for 18 length 'char' array is 80
The free space for 19 length 'char' array is 80
The free space for 20 length 'char' array is 80
The free space for 21 length 'char' array is 88
The free space for 22 length 'char' array is 88
The free space for 23 length 'char' array is 88
The free space for 24 length 'char' array is 88
The free space for 25 length 'char' array is 88
The free space for 26 length 'char' array is 88
The free space for 27 length 'char' array is 88
The free space for 28 length 'char' array is 88
The free space for 29 length 'char' array is 96
The free space for 30 length 'char' array is 96
The free space for 31 length 'char' array is 96
The free space for 32 length 'char' array is 96
The free space for 33 length 'char' array is 96
The free space for 34 length 'char' array is 96
The free space for 35 length 'char' array is 96
The free space for 36 length 'char' array is 96
The free space for 37 length 'char' array is 104
The free space for 38 length 'char' array is 104
The free space for 39 length 'char' array is 104
The free space for 40 length 'char' array is 104
The free space for 41 length 'char' array is 104
The free space for 42 length 'char' array is 104
The free space for 43 length 'char' array is 104
The free space for 44 length 'char' array is 104
The free space for 45 length 'char' array is 112
The free space for 46 length 'char' array is 112
The free space for 47 length 'char' array is 112
The free space for 48 length 'char' array is 112
The free space for 49 length 'char' array is 112
The free space for 50 length 'char' array is 112
The free space for 51 length 'char' array is 112
The free space for 52 length 'char' array is 112
The free space for 53 length 'char' array is 120
The free space for 54 length 'char' array is 120
The free space for 55 length 'char' array is 120
The free space for 56 length 'char' array is 120
The free space for 57 length 'char' array is 120
The free space for 58 length 'char' array is 120
The free space for 59 length 'char' array is 120
The free space for 60 length 'char' array is 120
The free space for 61 length 'char' array is 128
The free space for 62 length 'char' array is 128
The free space for 63 length 'char' array is 128
The free space for 64 length 'char' array is 128
The free space for 65 length 'char' array is 128
The free space for 66 length 'char' array is 128
The free space for 67 length 'char' array is 128
The free space for 68 length 'char' array is 128
The free space for 69 length 'char' array is 136
The free space for 70 length 'char' array is 136
The free space for 71 length 'char' array is 136
The free space for 72 length 'char' array is 136
The free space for 73 length 'char' array is 136
The free space for 74 length 'char' array is 136
The free space for 75 length 'char' array is 136
The free space for 76 length 'char' array is 136
The free space for 77 length 'char' array is 144
The free space for 78 length 'char' array is 144
The free space for 79 length 'char' array is 144
The free space for 80 length 'char' array is 144
The free space for 81 length 'char' array is 144
The free space for 82 length 'char' array is 144
The free space for 83 length 'char' array is 144
The free space for 84 length 'char' array is 144
The free space for 85 length 'char' array is 152
The free space for 86 length 'char' array is 152
The free space for 87 length 'char' array is 152
The free space for 88 length 'char' array is 152
The free space for 89 length 'char' array is 152
The free space for 90 length 'char' array is 152
The free space for 91 length 'char' array is 152
The free space for 92 length 'char' array is 152
The free space for 93 length 'char' array is 160
The free space for 94 length 'char' array is 160
The free space for 95 length 'char' array is 160
The free space for 96 length 'char' array is 160
The free space for 97 length 'char' array is 160
The free space for 98 length 'char' array is 160
The free space for 99 length 'char' array is 160
The free space for 100 length 'char' array is 160

g++ (gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)) on Fedora 14 32 bit/ Core i3 370M:

char array
The free space for 1 length 'char' array is 16
The free space for 2 length 'char' array is -16
The free space for 3 length 'char' array is 16
The free space for 4 length 'char' array is -16
The free space for 5 length 'char' array is 16
The free space for 6 length 'char' array is -16
The free space for 7 length 'char' array is 16
The free space for 8 length 'char' array is -16
The free space for 9 length 'char' array is 16
The free space for 10 length 'char' array is -16
The free space for 11 length 'char' array is 16
The free space for 12 length 'char' array is -16
The free space for 13 length 'char' array is -32
The free space for 14 length 'char' array is -32
The free space for 15 length 'char' array is -32
The free space for 16 length 'char' array is -32
The free space for 17 length 'char' array is -32
The free space for 18 length 'char' array is -32
The free space for 19 length 'char' array is -32
The free space for 20 length 'char' array is -32
The free space for 21 length 'char' array is -56
The free space for 22 length 'char' array is -56
The free space for 23 length 'char' array is -56
The free space for 24 length 'char' array is -56
The free space for 25 length 'char' array is -56
The free space for 26 length 'char' array is -56
The free space for 27 length 'char' array is -56
The free space for 28 length 'char' array is -56
The free space for 29 length 'char' array is -88
The free space for 30 length 'char' array is -88
The free space for 31 length 'char' array is -88
The free space for 32 length 'char' array is -88
The free space for 33 length 'char' array is -88
The free space for 34 length 'char' array is -88
The free space for 35 length 'char' array is -88
The free space for 36 length 'char' array is -88
The free space for 37 length 'char' array is -128
The free space for 38 length 'char' array is -128
The free space for 39 length 'char' array is -128
The free space for 40 length 'char' array is -128
The free space for 41 length 'char' array is -128
The free space for 42 length 'char' array is -128
The free space for 43 length 'char' array is -128
The free space for 44 length 'char' array is -128
The free space for 45 length 'char' array is -176
The free space for 46 length 'char' array is -176
The free space for 47 length 'char' array is -176
The free space for 48 length 'char' array is -176
The free space for 49 length 'char' array is -176
The free space for 50 length 'char' array is -176
The free space for 51 length 'char' array is -176
The free space for 52 length 'char' array is -176
The free space for 53 length 'char' array is -232
The free space for 54 length 'char' array is -232
The free space for 55 length 'char' array is -232
The free space for 56 length 'char' array is -232
The free space for 57 length 'char' array is -232
The free space for 58 length 'char' array is -232
The free space for 59 length 'char' array is -232
The free space for 60 length 'char' array is -232
The free space for 61 length 'char' array is -296
The free space for 62 length 'char' array is -16
The free space for 63 length 'char' array is -16
The free space for 64 length 'char' array is -16
The free space for 65 length 'char' array is -16
The free space for 66 length 'char' array is -16
The free space for 67 length 'char' array is -16
The free space for 68 length 'char' array is -16
The free space for 69 length 'char' array is -16
The free space for 70 length 'char' array is -16
The free space for 71 length 'char' array is -16
The free space for 72 length 'char' array is -16
The free space for 73 length 'char' array is -16
The free space for 74 length 'char' array is -16
The free space for 75 length 'char' array is -16
The free space for 76 length 'char' array is -16
The free space for 77 length 'char' array is -16
The free space for 78 length 'char' array is -16
The free space for 79 length 'char' array is -16
The free space for 80 length 'char' array is -16
The free space for 81 length 'char' array is -16
The free space for 82 length 'char' array is -16
The free space for 83 length 'char' array is -16
The free space for 84 length 'char' array is -16
The free space for 85 length 'char' array is -16
The free space for 86 length 'char' array is -16
The free space for 87 length 'char' array is -16
The free space for 88 length 'char' array is -16
The free space for 89 length 'char' array is -16
The free space for 90 length 'char' array is -16
The free space for 91 length 'char' array is -16
The free space for 92 length 'char' array is -16
The free space for 93 length 'char' array is -16
The free space for 94 length 'char' array is -16
The free space for 95 length 'char' array is -16
The free space for 96 length 'char' array is -16
The free space for 97 length 'char' array is -16
The free space for 98 length 'char' array is -16
The free space for 99 length 'char' array is -16
The free space for 100 length 'char' array is -16

The comparison makes clear that the old MinGW version of gcc is quite inefficient in allocating memories as far as two consecutive malloc()s are concerned. On the other hand other two compilers are quite good, and Fedora version of GCC exhibits a strange pattern. I didn’t note the kernel version of the Fedora 14 I have installed. I may test it on other systems, modify this experiment and post the results.

Readers are welcome to post their results.

Fluidity Experiment

Today, I started this new experiment of making things look fluid. The problem with fluid simulations is that they take a lot of computation and requires over-the-top mathematics which I am not familiar with. Thus I started making program that would simply make things look fluid, with simplest computation possible. My AVS preset making skills finally paid off, and I was able to incorporate some fluidity in my screen, as you can see in the video,

This Processing sketch (Program) makes this circles look like parts of an viscous somewhat like electrically charged fluid, with the mouse cursor be a controlled electrode. It was fun to code, tweaked the functions and the parameters to make the whole thing look nice and perfect in my computer. Different computer will give differently timed outputs as the program is not constrained with time. It will run independently on the systems’ resources.

The sketch can be downloaded from here (Fluidity.rar). I have this bad habit of not commenting while coding, and be too lazy for commenting in the end. This is my first processing sketch where I used custom classes for better coding. I found out that with classes I can make stuff with significantly less complex code, obviously at the cost of performance I guess.

It would be better if I could do this with OpenFrameworks, would get a lot more speed. I will do that someday, but for now I am satisfied with Processing. Its’ built in random number generator. I will further enhance the fluid function that drives the fluid mechanics of the circles and maybe able to get a nicer effect of fluid. Also I would like to use Computer Vision to interact with this fluid with webcams and hands.

Numeric Patterns Part 2

I tried to expand my numeric patterning  and found another technique that is able to make patterns from numbers which is more obscure than the previous technique. I believe this patterning technique will reflect memorability of a number in a better way. I still need to do a survey though. The detailed description of the algorithm is a little complex and also boring, so I leave it to the code readers. Nothing special in the algorithm.

The images are generated with Processing language. The sketch is here (Data_Painting_Part_2_pattern_and_number.rar). Download it, edit the text file ‘data.txt’ and run the sketch. The sketch will generate images of the numbers in separate .GIF files in the Images folder.

Numeric Patterns Part 1

I was exploring this idea of data painting, which is much like data visualization without being ‘meaningful’ essentially. I started with an idea of determining the simplicity of the number in term of remembering the number.

I started with a simple algorithm which would reflect the randomness of the sequence of numbers, which in turn would tell the viewer that the number is easily memorized or not. I started to work with Processing. Parsing numbers that is written on a text file.

Getting a suggestion from a friend, I decided to color the lines, but I always get in trouble coloring stuff with random number. He gave me the answer, BORDERS. And that was it, I changed and tweaked the program, added a few borders and that was it. The next picture is of my number again, colored. The color is decided by the last 6 digits of the number.

The idea is simple. The point starts from an arbitrary position. The program checks the next digit, and compares it with the current digit. The slopes in various places on the pattern indicate either the next number is greater, less or equal with the current number.

For example, let’s consider the number, 12537043332. For this number, the pattern is,

If you look at the details (from left) we will see that the 1st digit is smaller that 2nd, and there is a positive slope. Like wise, the first negative slope indicates 5 and 3. The string ‘333’ is indicated by that long straight near the end of the number.

Here are a few patterns that I generated.

There is a glitch with the co-ordinate system. Was being too lazy to fix that!

Here the link to the Processing sketch in Zip Files. The input should be a text file named ‘data.txt’ in the same folder containing the numbers with one number in a line (for the no name version). There is also another one designed to generate patterns from phone numbers with names. For that, do also put your name left to the phone number in ‘data.txt’. The outputs will be in GIF format in the sketch folder. Ignore the file names, my initial plan was reflected in the file names.

‘Custom function’ generator

Initially I planned to make a custom function generator which will be able to store waveforms, can be interfaced with computers, can be self contained, with a LCD as the UI, and would be able to produce bipolar waveforms with adjustable amplitudes and frequencies.

My first trial went in the attempt of running a 128×64 graphic LCD module with a PIC18F4550. After a little experimentation and brainstorming I realized that PIC18F4550 didn’t have enough RAM to run the display routines and generate the functions, let alone interfacing with the computers. I stopped trying,

A few days after my first failure of running the Graphic LCD module I learned about this emulated USB-serial library from Microchip. I thought it would be very cool when I will interface with the computers. From the start the PIC architecture scares me a little. Maybe that is because I am more accustomed with AVRs.

Few days ago I got this AVRISP mkII from Atmel and I started to work on the function generator. First I wrote a Processing sketch that would be used to ‘paint’ the waveforms. When the painting program was done, I started to rummage samples of DACs I got as samples from Texas Instruments. I find their service of samples really helpful for students like me.

I settled with the DAC TLC7226, it’s a quad DAC with 8-bit input. Has unipolar operation and can work in latched and transparent mode. After looking at the Datasheet I started wiring the DAC with an ATmega8 on breadboard. Within a few minutes I could get analog signals in my DSO nano.

Then I thought of bipolar signalling, although I left the electrical circuit part for unipolar to bipolar conversion for later, I started writing the AVR firmware for bipolar signalling with adjustable frequency which will be adjustable from the PC with UART communication line.

After I  coded a little, I started to test processing with the Bluetooth modem I had with me. I found out that it’s really a hassle free serial cable replacement but it won’t work with Processing. After a lot of tweaking the Processing IDE, I slid in the ExpressCard which adds Serial(RS-232) and Parallel port to my laptop and used my old custom made MAX232 board.

Then I started to code Processing sketch and the firmware almost simultaneously, trying to make a serial communication work. After an evening of bugging and debugging, I decided to strip down features and make a simple unipolar fixed frequency signal generator. After a while I was having trouble with the serial communication and found out that the problem was the slowness of the AVR and the speed of the PC. Even if I get the bauds right, the UART buffer in AVR is pitifully small and cannot handle all the bytes sent to it, so I added delay to the serial transmission from the PC. After getting the delays right, I found trouble in managing the UART routines in AVR. I decided to use interrupts with flags and got it done!

Ultimately I got the thing running and updating waveforms that was given from the PC. Then I added this frequency adjustment feature and I was at my first version.

This is the hardware on breadboard, and my custom breadboard AVRISP 6-pin programming header above. 🙂

Here’s the waveform generated, shown in DSO nano v2 running BenF firmware.

The circuit schematic is pretty simple I didn’t bother to document that. The AVR C (compiled with AVRGCC) code has all the necessary descriptions.

I uploaded the AVR Studio 5.0 project file and the processing sketch. Click here to download.

I couldn’t manage to get to higher frequencies, maybe with better designed routines I can push it a little more. My next stop would be to extending this function generator, with bipolar signal generation, amplitude control etc. For the the project is shelved. I have other things in mind.

Two waveforms and there DSO captures,