Tuesday, January 30, 2007

Motion Detection

Motion Detection
Setup:
* In order to get a better performance, I am using DVX100 instead of a webcam.
* The testing environment is in a normal room with normal lighting on the ceiling.

Overview:
The traditional motion detection can recognized the whole body motion. If I want to use motion detection to control an object which is on top of a real-time video streaming, I might only need to detect part of the body, such as hands or fingers. How can I filter out the unwanted part? Color detection or object detection might be the solution. Although AS2.0 can support edge detection, still a little bit complex to do the object detection. Color detection will be the easier way to do.
Below is my testing on 2 colors (Black & White) detection. In other words, it is the brightness detection. Below is my explanation:
Motion detection using 2 colors detection algorithm:

1. change the captured image to gray scale mode
var matrix4x5:Array = [0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0, 0, 0, 1, 0];//gray scale matrix
var gray:BitmapFilter = new ColorMatrixFilter(matrix4x5);
var myFilters:Array = [gray];
mc.filters = myFilters;//mc is the movieclip holder of the video

2. compare the current frame(now) to previous frame(before) and draw out the difference(now)
now.draw(before,m, null,'difference');//detecting the motion

3. filter out the dark gray level(value <>0xFFAAAAAA) to pure white(0xFFFFFFFF)
now.threshold(now, now.rectangle, now.rectangle.topLeft, '>', 0xFFAAAAAA, 0xFFFFFFFF);

5. find out the white color rectangle
re = now.getColorBoundsRect(0xffffffff, 0xffffffff, true);

6. if the location of an object is detected the white pixel, the motion event is trigger

Inside the video, I used a LED and tightened it on the index finger. As a result, the brightest area is on top of my index finger. Therefore, everything is filtered out except the LED ( the moving white dot on the right square). When my finger is moving with the LED light on, the white dot is moving as well. This is how the index finger motion is detected.
Below are the testing videos: (size = 320x240, the right square is to show the motion recognition)

Pressing a button



Dragging an object




Writing in the air- This video shows the resolution of the motion detection. Of course, if I linked the dots together, it is exactly writing.




Right now, I am still thinking how can I do the color detection without using external application, and of course using other methods than read in each pixel's value. Action script 2.0 can only support up to 4x5 matrix calculation. Will it be easier if I can convert RGB to HSV color space?

0 Comments:

Post a Comment

<< Home