Here’s a simple motion detection utility that you can use to do motion detection on a webcam, or video, or any other component in your Flex application. It uses a bitmap technique to compare image snapshots and calculate the number of pixels that were changed between snapshots. This gives you a percentage of the total pixels that were changed, which is a crude way to figure out motion. Basically what you do is draw one frame onto the previous frame using the “difference” blend mode. Then you threshold the image and you can figure out the number of pixels that had any change.
See the full example after the jump.
The example below uses the motion detector and ties it to a webcam. You’ll have to allow the app to access your webcam to see it in action. If the motion in the webcam exceeds a certain amount (20%), then it takes a snapshot and sends it to the CIA (ok, ok, it doesn’t really do that, it doesn’t send the snapshot anywhere).
Someone emailed me recently asking about this code, since it was shown in a previous video I created when I was working on TileUI a while back. This is the first in a series of chunks of code that I’m thinking about taking from that project and releasing open source. No, I don’t think I’ll be releasing all of TileUI, but just some of the components within it (like the radial menu component maybe).
P.S. I’ve been very quiet on the blogging front. This is because I’ve been super crazy mega busy between my job and writing Flex for Dummies, which is available for pre-order on Amazon. I expect to get back to blogging much more sometime after May 13 (after I sleep for a week).
- Pretty sweet logo, whoever designed that must be pretty much the best person in the world. Get your 360|Flex stuff here. And if you haven't registered for 360Flex, do that here.
- Since the next 360|Flex is fast approaching, I thought I'd post the full recording of my session at the last 360|Flex in Seattle. You can do whatever you want with this video, embed it wherever, watch it wherever, you can even download the original mp4 video file. Hopefully the embedded…