Example Code

Apply Calibration Information to an Image with Vision Assistant

Code and Documents

Attachment

This example demonstrates how to apply calibration information to an image using Vision Assistant.  This can be useful in many applications that require real-world measurements of objects in an image.  To get real-world values instead of just pixel measurements a calibration image can be used.  This allows the software to determine how many pixels are equal to the real-world units.

1. The first step is to develop a calibration image.  This image should have some sort of object or grid where the size in real-world units is known.  In the Image Calibration Script an image of a bracket is used.  The Image Calibration step applies the real-world measurement to the image.  For this example a simple, square calibration was chosen.  The distance between points 1 and 2 from the edge detection step was set to 10.00mm.

2. Once this script is run, the final image has calibration information associated with it.  The next step is to save this image as a PNG.  The "Save Extra Information" box must also be checked to store the calibration information with that image.

3. The template image can now be used to apply real-world units to other images*.  To use this image as a template the Calibration from Image step must be used.  If a measurement is then taken on the new acquired image, it will display the real-world units instead of just pixels.  This is shown in the Apply Calibration Script.

* It is important to note that the process images must be taken with the same camera at the same magnification and distance as was used to create the template image.  If there is a difference in distance or magnification the real-world measurements will not be accurate.

Justin D.

Applications Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors