Tutorial :Cocoa Touch - Detecting Motion?



Question:

Is it physically possible to have the iphone camera detect motion? If so, How do you do it?

Thanks!


Solution:1

You mean technically :) ? Physically it already does (in the sense of taping motion).

Technically you could use the interfaces defined in AVFoundation.framework, create bitmaps from selected frames and compare them. Usually you would make the images monochromatic (or turn them into binary images, it depends on your actual project), and compare the pixels. If a particular amount of connected pixels has changed, there must have been motion.

You would convert the images color space to gray-scale to have a better performance when comparing. It depends again on your project how many shades of gray you need. The picky part is the comparing algorithm for sure. A naive method would be just to count the changed (connected) pixels (making the image gray-scale can save you a lot of false positives). You could also do a Binary Search


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »