O'Reilly logo

QuickTime for Java: A Developer's Notebook by Chris Adamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making a Motion Detector

Capture isn’t just about writing data to disk. You can grab images as they come in and analyze or manipulate them.

Tip

A great example of “grabbing different” is Lisa Lippincott’s ScrollPlate, a demo shown at ADHOC 2004. She used her iSight camera as a scroll wheel, by holding up a Styrofoam plate with either a large green arrow (for up) or a large red arrow (for down). Her code presumably grabbed from the camera, looked at the grabbed image for an abundance of green or red, and scrolled the top window in response.

This example offers a simple motion detector, which will display an alarm message if two subsequent grabs are markedly different. The idea is that if the camera is not moving, a significant difference between two subsequent grabs indicates that something in view of the camera has moved.

How do I do that?

In this case, what you want to do is to set up video-only capture, but instead of saving the data to disk, you do a little bit of image processing each time you idle() . Specifically, there is a method in QTImage called getSimilarity( ), which compares two images (one as a QDGraphics and the other as an EncodedImage). Motion—objects entering, exiting, or significantly moving within the camera’s field of vision—can be understood as a significant difference between two consecutive grabbed images.

Note

See Chapter 5 for more on QTImage, QDGraphics, and EncodedImage.

Unfortunately, this requires jumping through quite a bit of QuickDraw hoops once ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required