Consoles, Smartphones, Tablets. Motion tracking is everywhere. Here is a simple way to utilise camera motion tracking in your Flash Projects.
A quick rundown on how the motion tracking demo works.
1. Take pictures.
Use the Camera and Video Object to get a steady stream of images. Write each image into BitmapData Object 1.
2. Create a time-delayed copy of each picture.
One frame (or TimerEvent) later copy BitmapData Object 1 into a second BitmapData Object (BitmapData Object 2).
3. Compare the two images.
Use BlendMode.DIFFERENCE to merge the two images. The originated image displays the differing parts between image one and two. Copy it into BitmapData Object 3. If you use the BitmapData function “getColorBoundsRect” you can now return a Rectangle Object. Whenever the with or height of this Object is bigger than 0 motion occurred.
In the Demo, a ColorMatrixFilter and a BlurFilter help to get rid of unimportant motion in the image (slight color changes or background motion). You can use a Sprite container with two added Bitmaps to store the first two BitmapData Objects. This gives you the option to apply filters to the container without having to reapply them every frame.
The example can also be used to create a simple spy cam, using Adobe Air to write BitmapData Object 3 to the File System. This application is also included in the download below.
You can download both motion detection demos, including their source files, from the following URL: