To download NI software, including the products shown below, visit ni.com/downloads.
This tutorial covers a preliminary step that is common to many machine vision applications: rotating a region of interest so subsequent image processing functions are applied to a correctly oriented image coordinate system.
In real-world conditions, the nature of mechanical inspection may require the machine vision algorithm to process an image that is not ideal. Consider the ideal image in Figure 1. The image is properly exposed and oriented plum and horizontally. This image is known as the reference image of the inspection. The reference image is the ideal representation of the object.
Figure 1: Properly Exposed and Symmetrically Oriented Image
Now consider the variants of Figure 1 shown in Figure 2. These images are of the same part, but they have been moved left, right, and rotated in the frame. These non-ideal images are typical in real-world conveyer-belt inspection systems. In order to obtain meaningful and relevant data from certain machine vision algorithms, the software must be able to coerce the non-ideal images to the reference image.
|
Figure 2: Properly Exposed but Asymmetrically Oriented Images
Various tools within the Vision Development Module are available to coerce the non-ideal images to the desired orientation.
LabVIEW 2014 or compatible
Vision Development Module 2014 or compatible
This tutorial will use the NI Vision Assistant to build a script that rotates the region of interest. Vision Assistant is capable of generating LabVIEW code from the script. We will work with sample images that ship with the Vision Development Module.
We have divided the implementation into four sections.
Open NI Vision Assistant from Start»Program Files»National Instruments»Vision Assistant »Vision Assistant.
Click Acquire Images»Simulate Acquisition. Your application will likely acquire from a camera. You have the opportunity to change the image source at any time.
Figure 3: Configure the Acquisition
In the Simulate Acquisition Setup area, click the file browser icon. Browse to C:\Users\Public\Documents\National Instruments\Vision\Examples\Images\Battery
in the file browser window and select Current Folder. Click Acquire Single Image until the reference image in Figure 1 appears and click Store Acquired Image in Browser. Click Close.
Figure 4: Obtain the Images
Click Process Images. We will now build a reference template by pattern matching against the reference image.
Select Pattern Matching from the Processing Functions: Machine Vision section. In the Template tab of the Pattern Matching Setup area, click New Template. Select an area of the reference image that will appear in all of the non-ideal images. Select the area by holding down the left mouse button and dragging around the area of interest. After you select the region of interest, you can resize the area by clicking on the corner of the area and dragging it to the desired size. In this example, we select the area containing the two holes and a portion of the paddle. Click Next.
Figure 5: Select the Region of Interest
Depending on the nature of the object, it may make sense to ignore certain areas of the region of interest. Perhaps a particular area of the object is manufactured inconsistently or is designed differently from one object to another. In this example, we'll choose to ignore most of the white space around the object itself. After you are done excluding areas, click Finish.
Figure 6: Ignoring Parts of the Region of Interest
You must now save the reference template. Choose a location other than the inspection image repository. Give the template a meaningful name and click OK.
In the Settings tab of the Pattern Matching Setup area, enable the Search for Rotated Patterns checkbox. Define the angle within which to search. In this example, we will specify Angle Range +/- (degrees) = 180, since we want to match the part no matter how much it's been rotated.
Notice that the reference template has a Score of 1000. This number is out of 1000, and indicates how exactly the current image matches the pattern of the reference template. Since this image is the reference template, it scores 1000 (it is a perfect match). You may return to this step and modify the default Score (800) depending on how reliably the reference template is discovered in the inspection image.
If you like, you may change the default name of the step from Pattern Matching 1 to a name of your choice. Switch to the Main tab of the Pattern Matching Setup and change Step Name. In this example, we have changed the name of the step to Pattern Match Reference Template (not shown). Click OK to close the Pattern Matching configuration.
We will now build a coordinate system based on the location and orientation of the reference template. From the Processing Functions: Image category, choose Set Coordinate System. Notice that the Pattern Matching step that you just configured appears in the Origin box of the Settings tab. Select the Mode that matches your object. In this example, we would like to find objects that have moved horizontally, vertically, and or rotated in the field of vision, so we select Horizontal, Vertical and Angular Motion.
Figure 8: Configuring the Coordinate System
If you like, you may change the default name of the step from Set Coordinate System 1 to a name of your choice. In this example, we have changed the name of the step to Set Reference Template Coordinate System. Click OK to close the Set Coordinate System Setup configuration.
We now have the ability to reference the coordinate system in any subsequent Machine Vision function. Your configuration will likely differ from this example.
For simplicity sake, let's do edge detection. From the Processing Functions: Machine Vision category, select Edge Detector. Switch to the Main tab of the Edge Detector Setup, and ensure that Reposition Region of Interest is checked and that the Reference Coordinate System refers to the coordinate system from the previous section.
Figure 9: Reference the Coordinate System During Processing
Switch to the Edge Detector tab of the Edge Detector Setup and configure the function. In this example, we'll detect all edges along a vertical line based on their absolute value. In this example, we have renamed the Edge Detector Step to Detect Edges on Rotated or Moved Parts.
Figure 10: Configure Edge Detection of the Reference Image
After you configure the inspection based on the reference image, save the script from File»Save Script. If you would like to test the script, click Original Image»Acquire Image»Simulate Acquisition»Acquire Single Image»Store Acquired Image in Browser»Close»Process Images. This loads a new image from the Battery folder into the image browser. Click Run Once, and the script will process the new image.
Figure 11: Image Processing on the Rotated Coordinates
Notice that the Edge Detection is performed on the rotated part. To evaluate the feasibility of the script within your application, select Tools»Performance Meter... The Performance Meter evaluates the script and gives you an idea of how many frames per second you can process with this script.
Figure 12: Performance Meter Evaluates Frames Per Second
Based on the performance of the script, we can expect to use it in applications that must process about 75 frames per second or fewer. You must consider other system requirements as well.
Generate LabVIEW Code
If you would like to use the script in LabVIEW, you can select Tools»Create LabVIEW VI... The Vision Assistant will use the functions and VIs in the Vision palette to build the VI. You will can build the script into a VI exactly as it appears in Vision Assistant, or you can customize the script's image source, inputs and outputs.
Figure 13: Configuring LabVIEW Inputs and Outputs
After Vision Assistant generates the LabVIEW code, you may modify it as you would any other VI. If you run the VI, it will perform as the script did. We have attached the Vision Assistant script file and the Reference Template to this document.
Alyssa H.
Applications Engineer
National Instruments
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
how to acquire real world coordinates of dust in an image using vision assistant??