Etiquetas

lunes, 11 de mayo de 2015

Artificial Vision 5 Inspecting an Object that Spans Two Image Frames

Inspecting an Object that Spans Two Image Frames

This example introduces the Select Image and Calculator steps.

Assume that you need to measure the width of a wide wooden plank with
high accuracy. The only cameras available for the application have low
pixel resolutions.

To measure the width of a plank, you need to locate its left and right edges.

If you were to set up the imaging system so both edges of a plank fit within
an available camera’s field of view, the resulting image detail would be too
low to yield accurate measurements. Because the required image detail
exceeds the pixel resolution capability of a single camera, two cameras per
plank are needed—one camera to acquire an image of the left edge and one
camera to acquire an image of the right edge.

Acquiring Inspection Images from Two Cameras


Acquiring and Calibrating the Image of the Left Edge


Complete the following instructions to configure Simulate Acquisition
steps that simulate acquiring an image of the left section of the wooden
plank and calibrating the image.

1. In the Inspection Steps palette, select the Acquire Images tab.

2. Click the Simulate Acquisition step. The property page for the step
opens.

3. In the Step Name control, enter Acquire Plank (Left).
4. Click the Browse button. The Select an Image File dialog box opens.
5. Navigate to <Vision Builder AI>\DemoImg\Tutorial 4 Left,
where <Vision Builder AI> is the location where Vision Builder
AI is installed.
6. Select the first image, Image 01.jpg, and click Open.

7. Make sure the Cycle Through Folder Images control is enabled so
that Vision Builder AI loads a different simulation image from the
folder each time the step is run.

8. Click the Calibration tab.

9. Click Create Calibration to launch the calibration wizard.
10. In the Calibration Name control, enter Plank Calibration
(Left).

11. Click Next.

For this example, assume that the camera that acquired the inspection
images is perpendicular to the image plane and lens distortion is negligible.
Based on these assumptions, you can use Simple Calibration to calibrate
your images. Simple Calibration transforms a pixel coordinate to a
real-world coordinate through scaling in the x (horizontal) and y (vertical)
directions.

12. Select the Simple Calibration option, and click Next.

13. Make sure Use Current Image is selected, and click Next.

14. Make sure Pixel Type is set to Square because the camera that
acquired the images for this exercise has square pixels.

15. Click Next.

16. In the Specify the Pixel Ratio step, carefully click the 1 cm and 5 cm
markings on the ruler at the bottom of the image, as shown in the picture.




17. In the Correspondence Image - Real World control, enter 4 for the
value, and select centimeter for the Unit.

18. Click Next.

19. In the Set Calibration Axis step, click the 1 cm marking to define it as
the origin of the calibration axis. Draw a line horizontally and to the
right along the edge of the ruler to define the angle of the calibration
axis, as shown in the next picture.



20. Set the Axis Reference control to Direct.

21. Click OK to learn the calibration information and exit the calibration
wizard.

22. Click OK to add the step to the inspection.

Acquiring and Calibrating the Image of the Right Edge


This section simulates acquiring an image of the right section of the
wooden plank. Because the simulated acquisition represents a second
camera, you cannot reuse the calibration that you created for the first
camera.

Complete the following instructions to configure Simulate Acquisition
steps that simulate acquiring an image of the right section of the wooden
plank and calibrating the image.

1. In the Inspection Steps palette, select the Acquire Images tab.

2. Click the Simulate Acquisition step. The property page for the step
opens.

3. In the Step Name control, enter Acquire Plank (Right).

4. Click the Browse button. The Select an Image File dialog box opens.

5. Navigate to <Vision Builder AI>\DemoImg\Tutorial 4
Right, where <Vision Builder AI> is the location where Vision
Builder AI is installed.
6. Select the first image, Image 01.jpg, and click Open.

7. Make sure the Cycle Through Folder Images control is enabled so
that Vision Builder AI loads a different simulation image from the
folder each time the step is run.

8. Click the Calibration tab.

9. Click Create Calibration to launch the calibration wizard.

10. In the Calibration Name control, enter Plank Calibration
(Right).

11. Click Next.

Again, assume that the camera that acquired the inspection images is
perpendicular to the image plane and lens distortion is negligible.

12. Select the Simple Calibration option, and click Next.

13. Make sure Use Current Image is selected, and click Next.

14. Make sure Pixel Type is set to Square because the camera that
acquired the images for this exercise has square pixels.

15. Click Next.

16. In the Specify the Pixel Ratio step, carefully click the 38 cm and
42 cm markings on the ruler at the bottom of the image, as shown in
the picture.



17. In the Correspondence Image - Real World control, enter 4 for the
value, and select centimeter for the Unit.

18. Click Next.

19. In the Set Calibration Axis step, click the 38 cm marking to define it
as the origin of the calibration axis. Draw a line horizontally and to the
right along the edge of the ruler to define the angle of the calibration
axis, as shown in the following picture.




20. Set the Axis Reference control to Direct.

21. Click OK to learn the calibration information and exit the calibration
wizard.

22. Click OK to add the step to the inspection.

Locating the Right Edge of the Part


Complete the following instructions to configure a Find Edges step that
locates the right edge of the part.

1. In the Inspection Steps palette, select the Locate Features tab.

2. Click the Find Edges step. The property page for the step opens.

3. In the Step Name control, enter Find Right Edge.

4. Draw a line across the right edge of the part going from right to left, as
shown in the picture.

Tip Pressing the <Shift> key while drawing a line constrains the line tool to only draw
horizontal or vertical lines.

5. Click the Settings tab.

6. In the Look for control, select First Edge.

7. In the Edge Polarity control, select Bright to Dark Only.




Notice the red square on the search line. The step searches along the
search line for a sharp transition in pixel intensities, which usually
represents an object edge. The red square marks the location of the
right edge of the part.

8. Click OK to add the step to the inspection.

Switching Images


Now that you have configured the inspection to locate the right edge of the
wooden plank, you need to switch to the image of the left side of the plank.
Complete the following instructions to configure a Select Image step that
makes the image of the left side of the plank active for processing.

1. In the Inspection Steps palette, select the Acquire Images tab.

2. Click the Select Image step. The property page for the step opens.

3. In the Step Name control, enter Switch to Left Side.

4. In the Image Selection list, select Acquire Plank (Left). The image
of the left side of the part appears in the Main window.

5. Click OK to add the step to the inspection.

Locating the Left Edge of the Part


Complete the following instructions to configure a Find Edges step that
locates the left edge of the part.

1. In the Inspection Steps palette, select the Locate Features tab.

2. Click the Find Edges step. The property page for the step opens.

3. In the Step Name control, enter Find Left Edge.

4. Hold down the <Shift> key and draw a line across the left edge of the
part going from left to right, as shown in next picture.

5. Click the Settings tab.

6. In the Look for control, select First Edge.

7. In the Edge Polarity control, select Bright to Dark Only.



The step searches along the search line and marks the location of the
left edge with a red square.

8. Click OK to add the step to the inspection.

Calculating the Width of the Part


Now that you have located the right edge of the part in one image and
the left edge of the part in another image, you need to combine the
measurements from the two images to determine the width of the part. Use
the Calculator step to combine the two measurements and compute the
width.

Refer to the following equations as you configure the step.

Right (LC) = Right (RC) + (Origin R – Origin L) 

Part Width = Right (LC) – Left (LC) 

where          Right (LC) = The x position of the right edge in the calibration
axis of the left edge.

                    Right (RC) = The x position of the right edge in the calibration
         axis of the right edge. This corresponds to the calibrated
x position result of the Find Right Edge step.

                    Origin R = The x position of the origin in the calibration axis of
the right edge.

                   Origin L = The x position of the origin in the calibration axis of
the left edge.

                     Left (LC) = The x position of the left edge in the calibration axis
               of the left edge. This corresponds to the calibrated x position
result of the Find Left Edge step.

Setting Calculator Step Inputs and Outputs


Complete the following instructions to configure a Calculator step to
select the input measurements from the previous Find Right Edge and
Find Left Edge steps, and create output results for the calculated values.

1. In the Inspection Steps palette, select the Use Additional Tools tab.

2. Click the Calculator step. The Calculator Setup Wizard opens.

3. Click Next to proceed with the wizard.

Notice the Input Measurements list. The list contains all of the
measurable data from each of the previous steps in the inspection.

4. Select the following measurements from the Input Measurements
list:

• Find Right Edge»Edge [1].X Position (Calibrated)

• Find Left Edge»Edge [1].X Position (Calibrated)

5. Click Next.

6. Click Add New Output Result. A new output appears in the Output
Results list.

7. In the Name control, enter Part Width. This output will contain the
results of Equation 5-2.
8. Make sure Type is set to Numeric.
9. Click Add New Output Result again.
10. In the Name control, enter Right (LC). This output will contain the
results of Equation 

11. Make sure Type is set to Numeric.

12. Click Finish to close the Calculator Setup Wizard.

The Main window now displays a diagram with the measurement inputs
and result outputs you specified in the Calculator Setup Wizard, as shown
in the next picture. The diagram also contains a default Boolean result named
Step Result. You can connect the result of a computation to Step Result,
which changes the status of the Calculator step to the result of the
computation. Refer to the Making Logical PASS/FAIL Decisions with the
Calculator Step section of this chapter for more information about Step
Result.





Notice that the inputs and outputs are framed with color and have codes at the
bottom of their frames. These colors and codes visually group inputs and
outputs into their respective data types—numerics, Booleans, or strings.

13. To simplify the process of connecting the diagram elements later in
this chapter, arrange the elements into the configuration shown in
the picture by dragging them to their new positions.




Adding Operators and Constants


Earlier in this chapter, you used the Calibration Wizard to set calibration
axis origins for the right and left sides of the part. These origins are the only
elements of Equations not yet represented in the Calculator
diagram: (Origin R and Origin L).

In step 19 of the Acquiring and Calibrating the Image of the Right Edge
section of this chapter, you set the origin of the right side to the 38 cm
marking of the imaged ruler. In step 19 of the Acquiring and Calibrating
the Image of the Left Edge section of this chapter, you set the origin of the
left side to the 1 cm marking of the imaged ruler. Therefore,
(Origin R – Origin L) = 38 – 1 = 37.

The distance between the calibration axis origins is a constant value. Add a
constant with the value 37 to the Calculator diagram.

1. In the Functions palette, click Numeric.

2. Click the Num Const operator. Click inside the Calculator diagram
below the Find Right Edge - Edge [1].X Position (Calibrated) input
measurement to place the numeric constant on the Calculator diagram.

3. Double-click the numeric constant and type 37 to set the value of the
constant.

4. Click the Add operator in the Functions palette. Click inside the
Calculator diagram to the right of the Find Right Edge - Edge [1].X
Position (Calibrated) input measurement.

Tip Place the Add operator close enough to the Find Right Edge - Edge [1].X Position
(Calibrated) input so that the Calculator step automatically connects the two elements
with a wire.

5. Click the Show Help Window button on the Main tab of the
Calculator step to launch the Help window, or click the Help button
in the Calculator diagram toolbar. When you move your cursor over
certain elements within the Calculator diagram, information about that
item shows in the Help window.

6. Place your cursor over the Add operator. Notice in the Help window
that the operator has an x input terminal, y input terminal, and
x+y output terminal.

7. Click the Subtract operator in the Functions palette. Click inside the
Calculator diagram to the right of the Find Left Edge - Edge [1].X
Position (Calibrated) input measurement.

Your Calculator diagram should look similar to the diagram shown in
the following picture.




Connecting the Equation Elements


Complete the following instructions to wire the diagram elements together
such that they form Equation 5-1: Right (LC) = Right (RC) + (37).

1. Place your cursor on the small, triangular terminal located on the right
side of the numeric constant. The cursor changes into a Wiring tool.

2. Use the Wiring tool to click the terminal and release the mouse. As you
move the cursor across the Calculator diagram, the Calculator step
draws a wire between the terminal and the Wiring tool as though the
wire were unwinding from a spool.

3. Without holding down the mouse button, move the cursor to the y input
terminal of the Add operator. The y input terminal blinks. Use the
Wiring tool to click the y input terminal and complete the connection.

4. Click the output terminal of the Add operator, and connect it to the
input terminal of Right (LC).

Tip If you do not terminate a wire correctly, the wire is broken and appears as a dashed
black line with a red X in the middle. Click Remove Broken Wires in the Main tab to
remove broken wires.

Complete the following instructions to wire the diagram elements together
such that they form Equation : Part Width = Right (LC) – Left (LC).

1. Place the cursor on the wire that connects the Add operator to
Right (LC). The cursor changes into the Wiring tool.

2. Click the wire, and connect it to the x input terminal of the Subtract
operator.

3. Click the Find Left Edge - Edge [1].X Position (Calibrated) output
terminal, and connect it to the y input terminal of the Subtract
operator.

4. Click the output terminal of the Subtract operator, and connect it to
the input terminal of Part Width.

Your connected Calculator diagram should look similar to the diagram
shown in the next picture.




5. In the Calculator step property page, click the Measurements tab.

6. Click Compute Results to see the results of the calculation thus far.

Making Logical PASS/FAIL Decisions with the Calculator Step


Now that you have a created a diagram to measure the width of the part,
you need a way to verify that the width meets manufacturing specifications.

Complete the following instructions to add diagram elements that compare
the measured width to minimum and maximum width tolerances and
decide whether the plank passes inspection.

1. Click the up arrow in the Functions palette to return to the main palette.

2. Select the Comparison palette.

3. Click the Less? operator in the Comparison palette. Click inside the
Calculator diagram below Part Width.

4. Connect the wire between Subtract and Part Width to the x input of
the Less? operator.

5. Click the up arrow in the Functions palette to return to the main palette.

6. Select the Numeric palette.

7. Click the Num Const operator in the Numeric palette.

8. Click close enough to the y input of Less? to automatically wire the
numeric constant and y input together.

9. Type 40.5 to set the maximum width a plank can be to pass the
inspection.

10. Click the up arrow in the Functions palette to return to the main palette.

11. Select the Comparison palette.

12. Click the Greater? operator. Click inside the Calculator diagram
below the Less? operator.

13. Connect the wire between Subtract and Part Width to the x input of
the Greater? operator.

14. Click the up arrow in the Functions palette to return to the main palette.
15. Select the Numeric palette.

16. Click the Num Const operator.

17. Click close enough to the y input of Greater? to automatically wire the
numeric constant and y input together.

18. Type 39.5 to set the minimum width a plank can be to pass the
inspection.

19. Click the up arrow in the Functions palette to return to the main palette.

20. Select the Boolean palette.

21. Click the And operator. Click close enough to the left side of Step
Result to wire the two elements together.

22. Connect the Less? output to the x input of And.

23. Connect the Greater? output to the y input of And.

Your completed Calculator diagram should look similar to the diagram
shown in the picture.




24. In the Calculator step property page, click the Limits tab.

25. Enable the Step Result is True checkbox.

26. Click OK to add the step to the inspection.

Setting the Inspection Status


Complete the following instructions to add a Set Inspection Status step to
determine whether the inspection passes or fails.

1. In the Inspection Steps palette, select the Use Additional Tools tab.

2. Click the Set Inspection Status step. The property page for the step
opens.

3. In the Inspection Status control, Select the FAIL if any previous
step fails option.

4. Click OK to add the step to the inspection.

Testing the Inspection


Test the inspection to make sure it returns the results you expect. Click the
Run Inspection Once button to test the remaining images. The next table lists
the test images, the inspection status to expect for each image, and an
explanation of the status.



Note Results may vary slightly based on the accuracy of the calibration and the edge
detection location.

Saving the Inspection





Artificial Vision 4 Inspecting for Multiple Correct Instances of an Object

Inspecting for Multiple Correct Instances of an Object

This example shows the Find Straight Edge, Size, and Decision
Making steps. Follow the instructions in this example to create a
inspection measuring the distance between a blade connectors
fuse and check the fuse integrity regardless of the fuse driver
position or if the fuse is reversed.

Complete the following instructions to configure a Simulate Acquisition
step that simulates acquiring images of fuses.

1. In the Inspection Steps palette, select the Acquire Images tab.

2. Click the Simulate Acquisition step. The property page for the step
opens.

3. In the Step Name control, enter Acquire Fuse.

4. Click the Browse button. The Select an Image File dialog box opens.

5. Navigate to <Vision Builder AI>\DemoImg\Tutorial 3, where
<Vision Builder AI> is the location where Vision Builder AI is
installed.

6. Select the first image, Image 01.jpg, and click Open.


Defining a Feature on which to Base a Coordinate
System


The fuses can appear shifted horizontally and slightly rotated from one
inspection image to another. Complete the following instructions to
configure a Find Straight Edge step that finds the left edge of the fuse so
that regions of interest in subsequent steps can shift with the fuse.

1. In the Inspection Steps palette, select the Locate Features tab.

2. Click the Find Straight Edge step. The property page for the step
opens.

3. In the Step Name control, enter Locate Fuse Left Edge.

4. Draw a region of interest (ROI) across the left edge of the fuse,
as shown in the picture


Notice that the ROI contains blue search lines. The step searches along
the search lines for sharp transitions in pixel intensities, which usually
represent object edges. The step fits a straight line through the
individual detected edge points of each search line to determine the left
edge of the fuse.

5. Click OK to add the step to the inspection

Setting a Coordinate System

Complete the following instructions to configure a Set Coordinate System
step based on the Find Straight Edge step you configured.

1. In the Inspection Steps palette, select the Locate Features tab.

2. Click the Set Coordinate System step. The property page for the step
opens.

3. In the Main tab, enter Set Coordinate System in the Step Name
control.

4. In the Settings tab, select Horizontal Motion from the Mode control.
Notice the Origin list. Point 1, the first point of the straight line
detected by the Locate Fuse Left Edge step, is the default origin of the
coordinate system. In this exercise, the location of the origin does not
affect the measurement you need to make. Therefore, use the default
origin.


5. Click OK to add the step to the inspection.

Measuring the Separation between Connectors


Complete the following instructions to configure a Caliper step that
measures the distance between the blade connectors of the fuse.

1. In the Inspection Steps palette, select the Measure Features tab.

2. Click the Caliper step. The property page for the step opens.

3. In the Main tab, enter Measure Separation in the Step Name
control.

4. Enable the Reposition Region of Interest control.

5. Draw an ROI across the blade connectors, as shown in the picture.


6. In the Settings tab, select the Process named Vertical Min Caliper to
change the direction and orientation of the caliper search lines.

7. In the Limits tab, enable the Minimum Distance control and set the
value to 150. Enable the Maximum Distance control and set the value
to 160.

8. Click OK to add the step to the inspection.

Inspecting the Fuse Conductor


Complete the following instructions to configure Match Pattern steps that
inspect the integrity of the fuse conductor.

1. In the Inspection Steps palette, select the Locate Features tab.

2. Click the Match Pattern step. The NI Vision Template Editor opens.

3. Draw an ROI around the conductor, as shown in the next picture. This
region becomes the pattern matching template.


4. Click Next.

5. Click Finish to accept the template.

6. On the Main tab, enter Match Conductor 1 in the Step Name
control.

7. Make sure the Reposition Region of Interest control is enabled.

8. Redraw or decrease the default green ROI so that it surrounds an area
slightly larger than the template, as shown in the next picture.




9. In the Settings tab, set Number of Matches to Find to 1.

10. Enable the Search for Rotated Patterns control.

11. Set the Angle Range +/– (degrees) control to 10 to enable the step to
locate the best match possible within ±10° of the learned template
angle.

12. In the Limits tab, enable the Minimum Number of Matches control
and set the value to 1.

13. Click OK to add the step to the inspection.

14. Click the Run Inspection Once button twice so that Image 03.jpg
becomes the active image.


A fuse may be inverted when Vision Builder acquires an image of the
fuse. This inversion causes the conductor to look different than the
template, shown in the picture a. To prevent a good but inverted fuse from
failing inspection, you need to learn a pattern matching template for the
inverted instances of the conductor as well, shown in the picture b.

15. In the Inspection Steps palette, select the Locate Features tab.

16. Click the Match Pattern step. The Select a template in the image
dialog box opens.

17. Draw an ROI around the conductor, similar to the region you drew in
step 3.

18. Click OK to learn the inverted template.

19. In the Step Name control, enter Match Conductor 2.

20. Set the Region of Interest control to Match Conductor 1. This
configures the Match Conductor 2 step to use the same ROI that you
previously defined for the Match Conductor 1 step.

21. In the Settings tab, set Number of Matches to Find to 1.

22. Enable the Search for Rotated Patterns control.

23. Set the Angle Range +/– (degrees) control to 10 to enable the step to
locate the best match possible within ±10° of the learned template
angle.

24. In the Limits tab, enable the Minimum Number of Matches control
and set the value to 1.

25. Click OK to add the step to the inspection.

Making Logical PASS/FAIL Decisions


In the previous examples, the inspection would fail if any of the steps in the
inspection failed. In this lesson, because the conductor under inspection can
match only one of the patterns you specified, one of the Match Pattern
steps always fails. If you were to set the Inspection Status to fail if any of
the steps in the inspection fail, the entire inspection will always fail because
one of the Match Pattern steps always fails.

Using the Logic Calculator step, you can create a Boolean result that is
based on the results of the previous inspection steps. The Set Inspection
Status step can use this Boolean result to determine the Inspection Status.
Complete the following instructions to configure a Logic Calculator step
that causes the inspection to pass when the conductor matches either the
template in Match Conductor 1 or Match Conductor 2, and when the
Measure Separation step passes.

1. In the Inspection Steps palette, select the Use Additional Tools tab.

2. Click the Logic Calculator step. The property page opens in the Main
window.

3. In the Step Name control, enter Decide Pass/Fail.

4. In the First Operand frame, set Source to Measure Separation.
Set Measure to Step Status.

Current Value displays the value of the measurement based on the
current image.

5. Make sure Second Operand is set to Constant, and Constant is set
to True.

6. Click Add to add this expression to the Expression table.

7. In the First Operand frame, set Source to Match Conductor 1.
Set Measure to Step Status.

8. Make sure Second Operand is set to Constant, and Constant is set
to True.

9. Click Add to add this expression to the Expression table.
Notice the default binary operator AND in the last column of the
Expression table.

10. In the First Operand frame, set Source to Match Conductor 2.
Set Measure to Step Status.

11. Make sure Second Operand is set to Constant and Constant is set
to True.

12. Click Add to add this expression to the Expression table.

13. Select the second expression in the Expression table, and click
AND/OR to change the binary operator to OR.

14. Hold down the <Shift> key, and select the second and third expressions
in the Expression table.

15. Click ( ) to group the expressions.
The Logic Calculator property page should resemble the picture.




16. Click OK to add the step to the inspection.


Setting the Inspection Status



Complete the following instructions to configure Vision Builder AI to pass
the inspection when the Logic Calculator step passes, regardless of the
results of individual steps in the inspection.

1. In the Inspection Steps palette, select the Use Additional Tools tab.

2. Click the Set Inspection Status step. The property page for the step
opens.

3. In the Step Name control enter Set Inspection Status.

4. In the Inspection Status control select the Equals specified
measurement option, and select Decide Pass/Fail - Step Status for
the value.

5. Make sure the Update Number of Parts Inspected control is enabled.

6. Click OK to add the step to the inspection.

Testing the Inspection



Test the inspection to make sure it returns the results you expect. Click the
Run Inspection Once button to test the remaining images. The next table lists
the test images, the inspection status to expect for each image, and an
explanation of the status.




Artificial Vision 3 Inspecting Objects for Correct Measurements

In this example we will see how the image calibration and object detection is performed. With the following instructions will see we create a
inspection to measure the distance between the holes in a board to verify
the board meets the required manufacturing specifications.

We will follow the following instructions to configure a Simulate Acquisition
step that simulates image acquisition boards.

1. Inspection Steps palette, select the tab acquire images.
2. Click the Simulate Acquisition step. The property page for step
opens.
3. Step Name control, enter Acquire Board.
4. Click the Browse button. The Select an image file dialog opens.
5. Navigate to <Vision Builder AI> \ DemoImg \ Tutorial 2 where
<Vision Builder AI> is the location in Vision Builder AI is
installed.
6. Select the first image 01.jpg image and click Open.
7. Ensure that cycle through the Control Pictures folder is enabled for Vision Builder load a different image in the folder each time the step is executed.
8. Click the Calibration tab.
9. Click Create Calibration to start the calibration wizard.
10. In the Name of the calibration check, enter calibration Board.
11. Click Next.

For this example, assume that the camera that took the inspection
images is perpendicular to the plane of the image.
Based on these assumptions, you can use Simple calibration to calibrate
their images.

12. Select the Simple calibration and click Next.
13. Make sure you select Use Current image and click Next.
14. Make sure Type is set to Color Square since the camera
acquired images for this exercise has square pixels.
15. Click Next.
16. In step of specifying the relationship Pixel, click 0 mm and
50 mm in the rule at the bottom of the image, as shown in
the picture.



17. In the Correspondence Image - Real World control, enter 50 for the
value, and select millimeter for the Unit.
18. Click Next. In the Set Calibration Axis step, you can define the origin and angle of the
calibration axis anywhere in the image. By default, the top, left pixel in the
image is the calibration axis origin, and the horizontal axis of the image is
the calibration axis angle.
19. Click OK to learn the calibration information and exit the calibration
wizard.
20. Click OK to add the step to the inspection

Locating Features to Measure


Complete the following instructions to configure a Detect Objects step that
finds small holes in the gasket.

1. In the Inspection Steps palette, select the Check for Presence tab.
2. Click the Detect Objects step. The property page for the step opens.
3. In the Step Name control, enter Detect Small Holes.
4. Using the default Rectangle Tool, draw a region of interest (ROI)
around the entire gasket, as shown in the picture.



5. In the Threshold tab, select the Bright Objects option for the Look
For control.
Notice that the blue shading highlights all bright pixels—pixels with
high intensity values that fall within the Threshold Range—in the
ROI.
6. Click the Settings tab.
The passage located four objects, listed in the following table. Depending on the location of points defined by the user in step Calibrate Image
previously configured, the values ​​for the size (mm2) may differ
slightly from the values ​​shown in the table.



Items 1 and 4 are the small holes of interest in this step. the
The following steps describe how to use the minimum object size and
Controls maximum size of objects by detecting objects step out
objects of interest based on their size.
7. Enable the size of the minimum and maximum object size objects
controls.
Based on the information in the table, the small holes have sizes
61.97 mm2 and 6104 mm2.
8. Establish minimum object size 50 and maximum object size to 70.
9. On the Limits tab, enable the minimum number of objects and
Maximum number of controls Objects. Set its value to 2.
10. Click OK to add the step to the inspection.


Complete the following instructions to find the large hole in the gasket.



1. Right-click the Detect Small Holes step in the State Configuration
window, and select Copy.
2. Right-click the Detect Small Holes step again.
3. Select Paste. A copy of the Detect Small Holes step is placed after the
original step.
4. Double-click the Detect Small Holes copy or click the Edit Step
button to launch the property page of the step for editing.
5. In the Step Name control, enter Detect Large Hole.
6. Select the Settings tab.
Based on the information in table, the large hole has a size of
1399.71 mm2.
7. Set Minimum Object Size to 1300 and Maximum Object Size
to 1450.
8. In the Limits tab, enable the Minimum Number of Objects and
Maximum Number of Objects controls. Set their values to 1.
9. Click OK to add the step to the inspection.

Measuring Parts of the Gasket


1. In the Inspection Steps palette, select the Measure Features tab.
2. Click the Geometry step. The property page for the step opens.
3. In the Step Name control, enter Check Top Distance.
4. In the Geometric Feature control, select the Distance measurement.
5. Select points 1 and 3 by clicking the points in the image or selecting
the points from the Available Points list.
6. In the Limits tab, enable the Minimum Distance control and set it
to 32. Enable the Maximum Distance control and set it to 35.
7. Click OK to add the step to the inspection.


Complete the following instructions to measure the distance from the large
hole to the bottom small hole to inspect whether the distance meets
specifications.

1. Right-click the Top Distance step in the State Configuration window,
and select Copy.
2. Right-click the Top Distance step again.
3. Select Paste. A copy of the Top Distance step is placed after the
original step.
4. Double-click the Top Distance copy or click the Edit Step button to
launch the property page of the step for editing.
5. In the Step Name control, enter Check Bottom Distance.

Setting the Inspection Status



Complete the following instructions to add a Set Inspection Status step to
determine whether the inspection passes or fails.

1. In the Inspection Steps palette, select the Use Additional Tools tab.
2. Click the Set Inspection Status step. The property page for the step
opens.
3. In the Inspection Status control, select the FAIL if any previous step
fails option.
4. Click OK to add the step to the inspection.

Testing the Inspection



Test the inspection to make sure it returns the results you expect. Click the
Run Inspection Once button to run the inspection on each of the test
images. This table lists the test images, the inspection status to expect for
each image, and an explanation of the status.



Saving the Inspection



Complete the following instructions to save the example inspection.
1. Select File»Save or click the Save button on the toolbar.
2. Navigate to the location where you want to save the inspection.
3. In the File Name control, enter a name.
4. Click Save to save the inspection.

Artificial Vision 6 Branching and Decision Making

Branching and Decision Making

This chapter of Virtual Vision introduces the inspection state diagram and the Custom
Overlay step. Follow the instructions in this example to create an inspection
that checks the image for the presence of a spray bottle and, if a bottle is
present, transitions to another state to determine if the bottle has a cap. If
there is no spray bottle present in the image, the inspection moves on to the
next image.


Creating a New Inspection


Select File»New to load a new, blank Vision Builder AI inspection.

Creating the Inspection State Diagram


The configurable process model in Vision Builder AI is represented by a
state diagram. Complete the following instructions to create a state diagram
to define the inspection.

1. Click the Toggle Main Window View button on the toolbar to bring

the state diagram to the Main window.




2. Double-click the Inspect state to launch the Edit State Name dialog
box.

3. In the State Name control, enter Check Part Presence, and
click OK.

4. Right-click an open area on the state diagram and select Create New
State to add a new state to the inspection, as shown in the following picture. The
Edit State Name dialog box opens.



5. In the State Name control, enter Inspect Part.

6. Create two more states named Fail Part and Pass Part. The state
diagram should now resemble the state diagram shown in the next picture.




Next, you will create transitions between the various inspection states.
Notice that every state has a default transition. You can also create
additional transitions between states based on measurement results or
variable values.

Note The default transition occurs if the transition requirements for other possible
transitions are not met.

7. Click the arrow of the Check Part Presence default transition and drag
it back to the Check Part Presence state. This creates a loop that will
run the steps in the Check Part Presence State until a part is detected.

8. Click the End point and drag it to the bottom of the state diagram.

9. Click the Inspect Part default transition and drag it to the Fail Part
state.

10. Click the Fail Part default transition and drag it to the End point.

11. Click the Pass Part default transition and drag it to the End point.


The state diagram should now resemble the state diagram shown in
the picture below.




12. Right-click the Check Part Presence state and select Create New
Transition.

13. Click the Inspect Part state to create a transition between the Check
Part Presence and Inspect Parts states, as shown in the next picture.




You can change the shape of the transition by dragging the anchor
point at the center of the transition. You can move the location of the
transition label by clicking the label and dragging it to the new
location.

Tip When drawing a transition, click once on the state diagram to set the anchor point for
the transition. The anchor point allows you to draw an arc instead of a straight line to
represent the transition.

14. Double-click the transition to launch the Edit Transition dialog box,
which is used to configure the transition.

15. In the Transition Name control, enter Part Detected, and
click OK.

16. Create another transition named Part OK between the Inspect Part
and Pass Part states.

The state diagram should now resemble the state diagram shown in
the picture.




Note You can remove a state or transition from the inspection by selecting the object you
want to remove and pressing the <Delete> key.

Note You cannot rename or remove the default transition of a state.

Each state in an inspection is intended to contain a separate set of inspection
steps. To access the functions in a state, click the state in the state diagram.

The currently selected state is highlighted in blue on the state diagram.

Acquiring Inspection Images


For simplicity, this tutorial instructs you to use the Simulate Acquisition
step. However, in your real-world inspection, use one of the other image
acquisition steps to acquire images of the object under inspection.

Complete the following instructions to configure a Simulate Acquisition
step that simulates acquiring images of spray bottles.

1. On the state diagram, click the Check Part Presence state.

2. In the Inspection Steps palette, select the Acquire Images tab.

3. Click the Simulate Acquisition step. The property page for the step
opens.

Note When the property page for an inspection step opens, if the state diagram is
displayed in the Main window, the state diagram switches from the Main window to the
Overview window to allow you to use the current inspection image to configure the step.

4. In the Step Name control, enter Acquire Image.

5. Click the Browse button. The Select an Image File dialog box opens.

6. Navigate to <Vision Builder AI>\DemoImg\Tutorial 5, where
<Vision Builder AI> is the location where Vision Builder AI is
installed.

7. Select an image containing the entire spray bottle, such as
Image 00480.jpg, and click Open.

8. Make sure the Cycle Through Folder Images control is enabled so
that Vision Builder AI loads a different simulation image from the
folder each time the step is run.

9. Click OK to add the step to the inspection.

Checking for a Spray Bottle in the Image


Complete the following instructions to configure a Match Pattern step to
check for the presence of a spray bottle in the image.

1. In the Inspection Steps palette, select the Locate Features tab.

2. Click the Match Pattern step. The NI Vision Template Editor opens.

3. Draw a region of interest (ROI) around the bottom left edge of the
bottle. This region becomes the pattern matching template.

4. Click Next.

5. Click Finish to accept the template.

6. On the Main tab, enter Locate Bottle in the Step Name control.

7. Adjust the default green ROI so that it only surrounds the area of the
image that could contain the bottom left edge of a spray bottle,
as shown in the next picture.




8. On the Settings tab, set the Number of Matches to Find control to 1.

9. On the Limits tab, enable the Minimum Number of Matches control,
and set the value to 1.

10. Click OK to add the step to the inspection.


Checking for the Cap Using the Caliper


You can check for the presence of the cap on a spray bottle by using the
Caliper step to find two edges where the cap is supposed to be and
measuring the distance between them. Complete the following instructions
to configure a Caliper step to check for the presence of the spray bottle cap.

1. In the Overview window, click the Inspect Part state on the state
diagram.

2. In the Inspection Steps palette, select the Measure Features tab.

3. Click the Caliper step. The property page for the step opens.

4. In the Step Name control, enter Check Cap Presence.

5. Draw an ROI around the area in the image where a cap should appear,
as shown in the picture.




6. On the Settings tab, select the Process named Horizontal Max
Caliper to change the direction and orientation of the caliper search
lines.

7. Set the Gap control to 10, Edge Strength to 40, and Smoothing to 12
to ensure that the step correctly detects the edges of the cap.

8. On the Limits tab, enable the Minimum Distance control, and set the
value to 140.

9. Enable the Maximum Distance control, and set the value to 160.

10. Click OK to add the step to the inspection.

Setting the Inspection Status


Complete the following instructions to add a Set Inspection Status step to
determine whether the inspection passes or fails.

1. In the Inspection Steps palette, click the Use Additional Tools tab.

2. Click the Set Inspection Status step. The property page for the step
opens.

3. In the Inspection Status control, select the FAIL if any previous step
fails option.

4. Click OK to add the step to the inspection.

Creating Custom Overlays for Inspection


Use the Custom Overlay step to create custom overlays that display
whether the inspection passed or failed.

Complete the following steps to create an overlay to display when the
inspection fails.

1. In the Overview window, click the Fail Part state on the state diagram.

2. In the Inspection Steps palette, select the Use Additional Tools tab.

3. Click the Custom Overlay step. The property page for the step opens.

4. In the Step Name control, enter Overlay Results.

5. On the Custom Overlay tab, select the Text tool and click a point in
the image near the bottom of the spray nozzle of the bottle.

6. In the Text Control, enter Missing Cap!.

7. Click the Text Properties button. The Text Properties dialog box
opens.

8. In the Desired Font control, select User-Specified Font.

9. Specify a Font Name and Size to use for the overlay.

10. In the Horizontal Alignment control, select Center. This centers the
text around the point you selected using the Text tool.

11. Click OK to save the Text Properties settings and close the dialog box.

12. Click OK to add the step to the inspection.

Next, you need to create an overlay to display if the inspection passes.
Complete the following steps to create an overlay to display when the
inspection passes.

1. In the Overview window, click the Pass Part state on the state
diagram.

2. In the Inspection Steps palette, select the Use Additional Tools tab.

3. Click the Custom Overlay step. The property page for the step opens.

4. In the Step Name control, enter Overlay Results.

5. On the Custom Overlay tab, select the Rectangle tool and draw a
rectangle in the upper-left corner of the image.

6. Click the Stroke control, and select black.

7. Click the Fill control, and select a bright green color.

8. On the Custom Overlay tab, select the Text tool, and click a point just
below the center of the rectangle overlay.

9. In the Text control, enter Part OK.

10. Click the Text color control, and select black.

11. Click the Text Properties button. The Text Properties dialog box
appears.

12. In the Desired Font control, select User-Specified Font.

13. Specify a Font Name and Size to use for the overlay.

14. In the Horizontal Alignment control, select Center.

15. Click OK to save the Text Properties settings and close the dialog box.

16. Click OK to add the step to the inspection.

The next picture shows the overlays for both Pass and Fail images.




Configuring State Transitions


Once you have configured all of the states in the inspection and created
transitions between the states, you need to define the conditions that trigger
a transition between inspection states. Complete the following instructions
to define the transitions between inspection states.

1. Click the Toggle Main Window View button to display the state
diagram in the Main window.

2. Double-click the Part Detected transition to launch the Edit
Transition dialog box, which is used to configure the transition.

3. In the Edit Transition dialog box, modify the controls to transition
when Locate Bottle - # Matches is Equal to 1, as shown in
the picture.




4. Click OK to close the Edit Transition dialog box.

5. Double-click the Part OK transition. The Edit Transition dialog box
opens.

6. In the Edit Transition dialog box, modify the controls to transition
when Check Cap Presence - Step Status is Pass, as shown in
the picture bellow.




7. Click OK to close the Edit Transition dialog box.

Testing the Inspection


Test the images in the Tutorial 5 folder to make sure the inspection
returns the correct results. Click the Run Inspection Once button to test
the remaining images. The next table displays the expected results for each
image.