Using Caliper Scoring FunctionsCognex VisionPro

The Caliper tool lets you define scoring functions that enable you to rank edge or edge pair candidates based on how well the meet your criteria. This topic shows how to define and use scoring function.

Measurement Caliper Walkthrough Use Scoring Functions ICog Caliper Scorer One Sided GetXYParameters diagram

This example assumes that you have created and configured a display control named cogDisplay1 that contains the image to analyze, and that you have configured a CogCaliper object named coCal.

Create and Initialize a Collection of Scoring Functions

This example shows the creation of two scoring functions, one that gives higher scores to results with higher edge contrast and one that gives a score of 1 for edge pairs that straddle the center of the input region and 0 for edge pairs that do not straddle the edge of the input region. (Note that since the TwoEdgeScorers collection contains a default CogCaliperScorerSizeDiffNorm object, this code uses three scoring functions, not just the two that you define.)

// Allocate the objects
coScoreStraddle = new CogCaliperScorerStraddle();
coScoreContrast = new CogCaliperScorerContrast();
coCal = new CogCaliperTool();

// Set the scorer parameters
coScoreContrast.SetXYParameters(100, 50, 20,1, 0.1);

// Add the scorers to the scorer collection
coCal.RunParams.TwoEdgeScorers.Add(coScoreStraddle);
coCal.RunParams.TwoEdgeScorers.Add(coScoreContrast);
Enable the Scoring Functions and Run the Tool

You can enable or disable individual scoring functions using the Enabled function. You can also enable or disable all of the functions in one of the scoring function collections by iterating through the collection.

// Enable or disable the scoring functions at run time based on user input
foreach (ICogCaliperScorer scorer in coCal.RunParams.TwoEdgeScorers)
    scorer.Enabled = cbEnabled.Checked;

// Set the input image and run the caliper tool
coCal.InputImage = (CogImage8Grey) cogDisplay1.Image;
coCal.Run();

// If we get a result, display its score
if (coCal.Results != null)
    if (coCal.Results.Count > 0)
        txtScore.Text = "Score: " + coCal.Results[0].Score.ToString();