A webcam image can be ‘grabbed’ at any point in time and stored as an ImageList image. With the static ‘grabbed’ image we can do further image processing using methods in LDImage.
One of the more interesting options is LDImage.DifferenceImages which creates a new image with each pixel value equal to the modulus of the difference of the two input images. In other words it is an image of ‘what has changed’. We can then further process this image to identify motion detection and even where something is or how it is moving.
This is the source code and a screenshot of a sample motion detection program that also shows a histogram distribution of the image colours (webcam/motion-detection.sb).
A recent example using this technique was provided by Zock77 to identify movement and control a turret to aim a gun. He used a very low resolution webcam image 16*16 pixels to simplify the calculation and identification of a moving target’s position.
The image on the right is the current webcam ‘grabbed’ image with 16*16 resolution expanded to fill a larger area. The image on the left is the ‘difference’ image showing movement since the initial image was reset (also expanded from 16*16 resolution), and the ‘cross hairs’ are the calculated center of the movement, which is used to control the turret using PPM (Pulse Position Moduation sound pulses and another extension).
The following 2 threads in the small Basic forum follow this development and there is also a YouTube video by Zock of it all working.