Virus scan in progress. Please wait to download attachments.
This VI demonstrates how you can use a camera as a means for motion detection. The basic idea here is to get a Boolean output to indicate whether there is motion in the frame or not. You can then use that Boolean output in other areas of your code. For example, you could make a VI that writes an AVI file, and only record frames when movement is detected.
To create this, we initially set up a Grab from a camera. Using low-level VIs, we can set the number of buffers that are allocated for the Grab. Inside the loop, we read out two images for each iteration. In this example, the frames have been specified to be 5 buffers apart. In other words, you will look at every fifth frame. The benefit of configuring the grab beforehand and reading images this way is that we can immediately access the images when we call the Read Image VI without having to wait for acquisition, since the acquisition is continuous.
Now we have two images that are separated in time by a small amount. The next step is to take the absolute value of the difference of these two images. This is a pixel-to-pixel operation. Any pixel values that are different between the two images will be brighter on the difference image. Typically the differences are fairly low values. So, for better visibility, it makes sense to multiply the result by a constant. In this VI, this constant is called "Pixel Gain". The Boolean decision of whether there is motion or not is determined by comparing the mean pixel value of the resulting image to a threshold value. This threshold value may need to be tweaked, based on the ambient conditions in your operating environment. This can be adjusted in this VI by using the control called "Mean Pixel Value Threshold".
Steps to Implement or Execute Code
Select your camera from the IMAQ or IMAQdx Session control on the front panel
Run the VI
Set the Pixel Gain control to a constant that the pixels in the differential image will be multiplied by
Set the Mean Pixel Value Threshold as a means of setting the sensitivity of the motion detector
LabVIEW 8.0 or later
Vision Acquisition Software
Versions for both IMAQ and IMAQdx have been included in the attachments
Additional Images or Video
**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**
Wes Pierce Principal Engineer Pierce Controls
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.