This application is used to show how a computer interacts with a human and converts his/her motion in command actions. It detects motion and converts that motion into the respective command actions.
To detect motion, it uses a simple algorithm of subtracting two images. Every image is made up of three layers: red, blue, and green. Thus, each of the pixels in an image holds three values corresponding to its RGB.
Using the Code
The above code snippet shows that it is easy to get a matrix of form
byte[,] from a bitmap image. Once you have two of such matrices from consecutive web-cam frames, you could subtract them to find the matrix that shows the motion in each of the pixels.
public ImageMatrix(Bitmap image)
this.width = image.Width;
this.height = image.Height;
byte[,] function = new byte[width, height];
unSafeBitmap usb = new unSafeBitmap(image);
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
this.function[i, j] = usb.GetAverage(i, j);
In the sample program I've provided with this article, there are five buttons:
You can also easily modify the code to control whatever you wish, or you could even add more virtual buttons! If you have questions about the program's functioning, then leave your comments here.