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.
No hay comentarios:
Publicar un comentario