Using Results AnalysisCognex VisionPro

Use a Results Analysis tool to define a set of criteria that will allow the last run of a tool group or CogToolBlock to be given an Accept, Warn, or Reject result. Using a Results Analysis tool, you can combine the results from one, several, or all the vision tools and generate a value that can be used to judge whether the tool group generates a Warn or Reject status. VisionPro ultimately uses this Warn or Reject status to determine the value of the Result property for the tool group.

Note: The Results Analysis tool is intended for use in QuickBuild applications. There is no programmatic interface to it.


To use Results Analysis, double-click on the CogResultsAnlaysisTool in the VisionPro toolbox. The following figure shows an empty Results Analysis tool dialog box:

Framework Tool Group Walkthrough Results Analysis Results Default Window

The dialog box contains a Settings tab for generating expressions that determine whether the tool produces a Warn or Reject status, and a Results tab for viewing the results of the expressions you define.

Expressions

To generate the criteria for an analysis, you must create one or more expressions needed to generate a result. The following figure shows an example expression:

Framework Tool Group Walkthrough Results Analysis Sample Grid Row

Ultimately, you must generate a result that can be expressed as a single boolean value, a value which can be used to determine the warning-level or reject-level result of the tool.

Argument Types

Each expression in a Results Analysis tool contains an operation on one or two arguments in order to produce a result. You can use the following types of arguments:

Table 1. Data Types
TypeDescription

Constant

You can specify a numeric, string, or boolean constant as an argument. For example, you can compare a vision tool result against the value 5, against the string value "Cognex", or against the boolean value True.

The following figure shows an example of a string constant in an argument field:

Framework Tool Group Walkthrough Results Analysis Sample Constant Terminal

The operation you choose allows the Results Analysis tool to determine whether the constant value you specify is valid. For example, if you choose a logic operation and specify the string "123" as an argument, the Results Analysis tool will report an error until you supply a boolean value.

Value Input

You can choose any numeric, string, or boolean result from a vision tool in your application.

The following figure shows an example of a value input:

Framework Tool Group Walkthrough Results Analysis Sample Value Terminal

The Results Analysis tool gives the value input a default name starting with Input. The section Creating Value Inputs and Vector Inputs describes how to add a value input to a Results Analysis dialog box.

Vector Input

While a value input lets you use the value of a single tool result, you can choose a vector input and allow Results Analysis to perform an analysis on the entire array of values in a collection. For example, if your application uses a Blob tool, you can choose all the Area results. The size of the vector would correspond to the number of area results for this Blob tool.

The following figure shows an example of a vector terminal in an argument field:

Framework Tool Group Walkthrough Results Analysis Sample Vector Terminal

Notice that the Results Analysis dialog box uses an ellipses [...] to distinguish it from a value input argument.

An operation that involves a vector terminal can produce a vector result. For example, if you perform an operation to compare a vector terminal against a string constant, the result is a vector of boolean values, with a value of True for each item in the vector that matches the string.

The Value field shows an ellipses [...] for a vector of values. You can click on the Value field to display the contents of the vector, as shown in the following figure:

Framework Tool Group Walkthrough Results Analysis Show Vector Values

The Results Analysis tool gives the value input a default name starting with Input. The section Creating Value Inputs and Vector Inputs describes how to add a value input to a Results Analysis dialog box.

Cell Reference

For many tool groups, a single operation between two arguments is not enough to determine the scalar boolean value for the entire Results Analysis. For example, if the first operation in a grid generates a vector result of boolean values, a second operation is likely needed to determine if any of the results equal True or False. When one operation relies on the result of a previous operation, you can specify the cell reference of the previous operation as an argument.

The following figure shows an example of a cell reference in an argument field:

Framework Tool Group Walkthrough Results Analysis Sample Cell Terminal

This argument uses the result of the expression ExprB as the first argument for the expression ExprC.

Operation Types

The Results Analysis tool offers the following operation types:

Table 2. Operation Types
TypeOperationsDescription

Arithmetic

Add

Subtract

Multiply

Divide

Perform the arithmetic operation on two numeric arguments.

Any nonzero result evaluates to a boolean value of True, while any zero result evaluates to a boolean value of False.

Numerical comparison

LessThan

LessThanOrEqual

GreaterThanOrEqual

GreaterThan

Generate a True or False result based on the comparison between the two numeric arguments.

Logic

And

Or

Xor

Generate a True or False result based on the logical comparison between the two arguments.

You can use constants, cells, value terminals, and vector terminals of boolean values as arguments. Any nonzero result evaluates to a boolean value of True, while any zero result evaluates to a boolean value of False.

LogicNotReverse the True or False value of the argument.

Reducing Logic

Logic And All

Logic Or All

The Logic And All operation reduces a vector of boolean values to True if all the values in the vector are True, and False one or more values are False.

The Logic Or All operation reduces a vector of boolean values to True if one or more values in the vector are True, and False if no values are True.

Unary Operators

Abs

Sqrt

Generate the absolute value or the square root of the numeric argument.

The tool offers the following vector processing operation types:

Table 3. Operation Types
OperatorDescription
CountThis operator takes a vector as Argument0 and outputs an integer whose value equals the number of elements in the supplied vector. It is an error for Argument0 to not be a vector.
MinThis operator takes a vector as Argument0 and outputs a double precision value that corresponds to the minimum value encountered in the supplied vector. It is an error for Argument0 to not be a vector. It is an error for any element in Argument0 to not be convertible to a double.
MaxThis operator takes a vector as Argument0 and outputs a double precision value that corresponds to the maximum value encountered in the supplied vector. It is an error for Argument0 to not be a vector. It is an error for any element in Argument0 to not be convertible to a double.
MedianThis operator takes a vector as Argument0 and outputs a double precision value that is the median of the values encountered in the supplied vector. It is an error for Argument0 to not be a vector. It is an error for any element in Argument0 to not be convertible to a double.
MeanThis operator takes a vector as Argument0 and outputs a double precision value that is the mean of the values encountered in the supplied vector. It is an error for Argument0 to not be a vector. It is an error for any element in Argument0 to not be convertible to a double.
SDevThis operator takes a vector as Argument0 and outputs a double precision value that is the standard deviation of the values encountered in the supplied vector. It is an error for Argument0 to not be a vector. It is an error for any element in Argument0 to not be convertible to a double.
SumThis operator takes a vector as Argument0 and outputs a double precision value that is the sum of the values encountered in the supplied vector. It is an error for Argument0 to not be a vector. It is an error for any element in Argument0 to not be convertible to a double.
SortThis operator takes a vector as Argument0 and outputs a new, equally sized vector that has been sorted into ascending order. It is an error for Argument0 to not be a vector. It is an error for any element in Argument0 to not support the “less than” comparison.
ReverseThis operator takes a vector as Argument0 and outputs a new, equally sized vector whose elements have been reversed in order. It is an error for Argument0 to not be a vector.

The tool offers other non-vector mathematical operators:

Table 4. Operation Types
OperatorDescription
ModThis operator takes two numerical arguments and outputs their modulus. That is, it divides Argument0 by Argument1 and outputs the remainder. It is an error for Argument1 to be equal to zero.
FloorThis operator takes a single numerical argument and outputs the largest integral value that is less than or equal to the supplied value.
CeilingThis operator takes a single numerical argument and outputs the smallest integral value that is greater than or equal to the supplied value.

The tool offers other non-vector mathematical operators:

Table 5. String Operations
OperatorDescription

StringEqual

StringEqualCaseInsensitive

Generate a True or False result based on the comparison between the two string arguments.

StringMatch

StringMatchCaseInsensitive

Generate a True or False result based on comparing the string in Argument1 to the string in Argument0.

For example, comparing the string "Cognex" to "Cognex Corporation" produces a True result, but comparing "Cognexx" to "Cognex Corporation" produces a False result.

StringToUpperTakes a single argument and maps any lower case characters to upper case, and outputs the resulting string.
StringToLowerTakes a single argument and maps any upper case characters to lower case, and outputs the resulting string.
StringLengthTakes a single argument and returns the integer number of characters in that string. An empty string has length zero.
StringAddTakes two arguments and returns a concatenation of the two.
StringIfTakes two arguments, a boolean and a string, and returns the string if the boolean argument is True, or returns an empty string if the boolean argument if False.
Creating Value Inputs and Vector Inputs

To create a value input or vector input to be used in a Results Analysis expression, perform the following steps:

  1. Add output terminals, as necessary, for any vision tool whose results you want to use in a Results Analysis tool.

    For example, a Barcode tool exposes the result for Count, but not the vector of all the Angle results.

  2. Add a Results Analysis tool to your QuickBuild job.
  3. Double-click on the Results Analysis tool to open the Results Analysis dialog box, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis Results Default Window

  4. Click the Add Input icon or the Add Vector Input icon on the Settings tab to create a value input or vector input, respectively. The following figure highlights these icons:

    Framework Tool Group Walkthrough Results Analysis RASettings Icons

    If you create a value input, it appears in the Results Analysis dialog box as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis RANew Value Row

    If you create a vector input, it appears in the Results Analysis dialog box as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis RANew Vector Row

    In addition, a new input terminal for the Results Analysis tool appears, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis RANew Input Terminal

    Note: If you delete this input terminal at any point in developing your application, you can restore it by right-clicking on the Results Analysis tool and selecting Add Terminals to open the CogFloatingPropertyBrowser window. Next, select the RunParams property, open the Item property corresponding to this value, and then open the CogResultsAnalysisVectorInputExpression or CogResultsAnalysisInputExpression property, whichever is valid for your input terminal. Finally, select the Value field and click Add Input at the bottom of the CogFloatingPropertyBrowser window. Close the CogFloatingPropertyBrowser window.

  5. In your QuickBuild job, click the "+" next to the CogResultsAnalysis tool to display the value input terminal or vector input terminal.
  6. Link the output terminal of the result you want to use to the appropriate value input terminal or vector input terminal. A vector input terminal requires a collection of valid results from a tool that has successfully generated results.

    For example, the following figure shows the output terminal of a Blob tool linked to the value input terminal of a Results Analysis tool:

    Framework Tool Group Walkthrough Results Analysis RACount To Terminal

    When you make the link with a value input terminal, the Results Analysis tool updates its dialog box with the current value, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis RAUpdating Value Terminal

  7. (Optional) Click inside the Name field and change the default name of the input to give it a more meaningful name for your application.
  8. If you are creating a vector input from a results collection, you must select which specific result you want in the Argument0 field. For example, the following figure shows the results of a Blob tool with the Elongation result selected:

    Framework Tool Group Walkthrough Results Analysis RASelected Elongation

Creating Expressions

To create an expression for a Results Analysis tool, perform the following steps:

  1. Add the value inputs and/or vector inputs you need to perform a Results Analysis. See the previous section for details.
  2. Click the Add Expression icon on the Settings tab. The following figure highlights this icon:

    Framework Tool Group Walkthrough Results Analysis RAExpression Icon

    A new expression appears in the Results Analysis dialog box as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis RANew Expression

  3. Select an operator from the Operator field. See the section Operation Types for a description of all the operators.

    Depending on the operator you select, the Results Analysis tool will enable one or both arguments in the expression. For example, the following figure shows an expression when the Add operator is used:

    Framework Tool Group Walkthrough Results Analysis RAAdd Operator

  4. Select the appropriate values for Argument0 and Argument1, as necessary.

    To use a constant value, type the value into the argument field. To use a value input or vector input, use the drop down list the field provides to select the appropriate argument. Be aware that if both arguments are vectors, they must be the same size or the expression cannot be successfully evaluated.

    After you select valid arguments based on the current operator, the Value field of the expression will update with a numerical, string, or boolean value. If the expression you created generates a vector result, the Value field shows [...].

Create as many expression as you need to generate a single True/False or zero/nonzero result. See the Example Application at the end of this topic for an example of how to create and link multiple expressions.

Output Expression

Every Results Analysis tool contains an Output expression that determines the overall result for the tool. The Output expression determines the Warning or Reject status of the tool by testing the singular result of another expression. This expression must evaluate to a boolean value or a numerical result. If you attempt to specify any vector of results for the Output expression, the Results Analysis tool will generate an error.

Perform the following steps to configure the output expression:

  1. Select Argument0 in the Output expression and choose either Warning or Reject.

    If you need your application to generate either a Warning status or a Reject status based on different criteria, use multiple Results Analysis tools.

  2. Select Argument1 and choose the expression that evaluates to a single boolean value or numerical result.

    If you are generating a Warning status or Reject status based on a boolean value, the value of the tool will equal the value of the expression you choose for Argument1. If you use an expression that evaluates to a numerical value, the Output expression will generate an Accept result if the value is zero or a Warning/Reject result if the value is nonzero.

  3. Test the application to ensure the Output expression generates the correct value.
Output Field

The last column of each expression contains an Output checkbox. For every expression with the Output checkbox enabled, the tool group will expose that value as an output terminal. Output terminals can be useful in applications where you use nested tool groups. For example, the following figure shows the expressions for a rejection-analysis with two of the equations exposed to the tool group:

Framework Tool Group Walkthrough Results Analysis Two Exposed Equations

The following figure shows how the exposed equations appear as output terminals for the tool group:

Framework Tool Group Walkthrough Results Analysis Two Output Terminals

In addition, you can specify the exact data and data type for the value of an exposed output terminal by right-clicking on one and selecting Modify, which launches the Modify Output Terminal dialog box:

Framework Tool Group Walkthrough Results Analysis Modify Output Terminal

Use the Modify Output Terminal dialog box to specify the exact value you want to expose. For example, the following figure shows the same CogResultsAnalysisTool as the previous figure where the expression ExprB has been replaced with its Boolean value:

Framework Tool Group Walkthrough Results Analysis New Modified Terminal

Example Application

The following procedure creates a QuickBuild application that decodes the barcode symbols in an IDB file and generates a warning result if any found symbol has a rotation of greater than 25 degrees.

  1. Launch QuickBuild, which by default contains one Job:

    Framework Tool Group Walkthrough Results Analysis Quick Start With Navigator

  2. (Optional) Close the Navigator pane.
  3. Double-click on the Image Source for CogJob1 and configure it to use the images in the file Cognex\VisionPro\Images\barcode.idb.

    See the section Acquiring Images from a File or Directory for details on acquiring from an image database.

  4. Create a CogBarcode tool and give it the OutputImage from the Image Source, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis How To Image File To Barcode

  5. Run the Job once to give the Barcode tool an input image.
  6. Open the Barcode tool edit control, which appears as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis How To Barcode With Image

    By default, the Barcode tool will locate and decode barcode symbols using only the Code 39, Code 128, UPC/EAN, and Code 93 symbologies.

  7. Enable the Interleaved 2 of 5 symbology in the Settings tab since the barcode.cdb file contains two images with an Interleaved 2 of 5 barcode symbol.
  8. Increase the NumToFind property to 4 to ensure that the tool locates all the symbols in each image. The tool does not fail if it does not find the number of barcode symbols it was configured to find.
  9. Switch to the LastRun.InputImage buffer in the edit control and execute the entire application from the tool group window.

    The Barcode tool will successfully locate and decode the symbols in the barcode.cdb image database. To view the decoded string of each symbol, switch to the Results tab. The following figure shows the Results tab and the LastRun.InputImage buffer for an image containing four UPC/EAN barcode symbols:

    Framework Tool Group Walkthrough Results Analysis How To BarcodeUPCEAN

  10. Close the Barcode tool edit control.
  11. Right-click on the Barcode tool in QuickBuild and select Add Terminals. Use the CogFloatingPropertyBrowser dialog box to expose output terminal for CogBarcodeResults.

    For example, the following figure shows the CogFloatingPropertyBrowser dialog box with the CogBarcodeResults selected.

    Framework Tool Group Walkthrough Results Analysis Results Selected

    Click Add Output to add an output terminal for this result. Click Close to close the CogFloatingPropertyBrowser dialog box.

  12. The Barcode tool in QuickBuild should now have the output terminals shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis How To Barcode All Terminals

  13. Create a CogResultsAnalysis tool and double-click on it to open the Results Analysis dialog box.

    An empty Results Analysis tool dialog box opens as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis Results Default Window

  14. Click

    Framework Tool Group Walkthrough Results Analysis Add Vector Input

    to add a vector input to the Results Analysis tool.

    The Results Analysis dialog box appears as shown in the following dialog box:

    Framework Tool Group Walkthrough Results Analysis Results InputA

  15. Close the Results Analysis tool dialog box for the moment.
  16. Click the "+" symbol next to the CogResultsAnalysisTool in QuickBuild to expose the input terminal, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis Results Analysis InputA

  17. Link the Results output terminal from the CogBarcodeTool to the InputA input terminal of the CogResultsAnalysis tool, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis Results Link InputA

    Next, you must create the expression that will generate a warning-level result if any found symbol has a rotation greater than 25 degrees.

  18. Re-open the Results Analysis dialog box, click inside the Argument0 field and scroll down to select the Angle result, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis Select Angle In Box

  19. Click

    Framework Tool Group Walkthrough Results Analysis Add Expression Input

    to add an expression to the Results Analysis tool:

    Framework Tool Group Walkthrough Results Analysis Results ExpressA

  20. Click inside the Operator field and select GreaterThan.
  21. Click inside the Argument0 field and select InputA.
  22. Click inside the Argument1 field and enter the value 0.43611.

    The Results Analysis tool requires degrees given in terms of radians, so you must convert the 25 degrees to approximately 0.43611 radians.

    Once you enter the Argument1 value, the Results Analysis tool evaluates the expression and generates a vector of boolean values, as shown in the following figure:

    Framework Tool Group Walkthrough Results Analysis Angle Vector Results

    This next expression evaluates all the boolean values from the previous expression and generates a single result of True if any value in the vector is True.

  23. Add another expression to the tool, click the Operator field, and select OrAll.
  24. Click the Argument0 field and select ExprA.
  25. Click inside the Argument0 field in the Output expression and select Warning.
  26. Click inside the Argument1 field and select ExprB.
  27. Run the application several times. The application will generate a warn-level result when the image contains at least one symbol with a rotation greater than 25 degrees. The following figure shows the Results Analysis dialog box when the application generates a warn-level result:

    Framework Tool Group Walkthrough Results Analysis Warn Level Result