Friday, October 16, 2009

Robotic eye

Real time tracking of objects is an exciting idea , now we will see how exactly to track
a coloured object
im using Matlab version R 2007b

1)CODE for video initializations

vid=videoinput('winvideo',1,'RGB24_640x480') ; // specifies the size of captured input image and format
triggerconfig(vid,'manual'); // triggering type
set(vid,'FramesPerTrigger',1); // frames acquired for trigger
start(vid); // start video capturing

after executing u can see an vid named object in ur workspace


2)How to get the image

trigger(vid);
temp= getdata(vid,1);

trigger the vid object , and then the frames will be logged onto buffers u can retrieve them using getdata function
In this code Temp object will have image 640x480 ,use this for processing

3) RBG colour space
temp is an 640x480 array and each element in the array has 3 slots (each of one byte) for RED GREEN BLUE
actually the input image is 3D array
accessing each element temp(X,Y,COLOUR);
temp(1,1,1) ; first element in R dimension
lly for green 2 and blue 3,

4) Extract region of interest colour
matlab supports an inbuilt function roicolor();

usage
BW1 = roicolor(temp(:,:,1),0,20); // BW1 has 1 where the values of temp(:,:,1) in between 0 and 20 and 0 else where
BW2 = roicolor(temp(:,:,2),0,20);
BW3 = roicolor(temp(:,:,3),0,20);

BW= BW1 & BW2 & BW3; // this is the final BW image

the values given to the roicolour will vary with light intensity and need to be calibrated again and again ...... :(

for example u want to follow a blue colour object first get a snapshot of ur object
then find the max and min value in RGB space in ur region of interest(object)
then feed those value
this can be done using roipoly() function and a median filter or average filter

5) Calculate center of gravity of the image
BW will have 1's where the object is present and zeros elsewhere
u can get Xavg and Yavg values and mark the object in the given image temp

6)Improvements : This is one way of doing but this is not that efficient in noisy environment
to get a more robust program which u can really upon go for morphological image processing techniques
BW has a lot of noise we have to filter it out using erosion followed by dilation
to get a smoothed BW image

this is what i got after all those 5 steps and adding noise rejection capability
vedio

This is one method , this does not given exact envelop of the object we are tracking we can only pinpoint its location
to enclose the object in a box if have used histogram analysis and this is 0.1 sec faster than the above method
and the diagonal intersection of the box will given u the center of gravity which more accurate
here's the vedio
click