LineMax Tool Edit ControlCognex VisionPro

The CogLineMaxTool edit control provides a graphical user interface to the CogLineMaxTool, which you use to locate candidate edge points and fit the best possible line segment based on criteria you specify:

See the topic Using a LineMax Tool for more information on the LineMax tool.

To include the edit control in your custom vision application, you must first add it to your Visual Studio .NET development environment. See the topic Adding Edit Controls to Visual Studio for more information.

Control Buttons

The CogLineMaxTool supports the following buttons along the top of the edit control:

ButtonDescriptionFunction
RunExtract candidate edge points and fit a line to those points, taking the present set of line-fitting parameters into consideration.
Electric modeToggle electric mode, where the tool executes automatically when you change the value of certain parameters. In electric mode, a lightning bolt appears next to every electric property.

Local image display

Open or close the local image display window. A LineMax tool supports the following image buffers:

  • The Current.InputImage buffer contains the input image and any graphics to represent the input region, the expected line normal graphic and any image mask.
  • The LastRun.InputImage buffer contains the input image and any graphics representing a fitted line and edge points that were used and not used.
Floating image displayOpen one or more floating image windows, which support the same image buffers as the local image display window.
OpenOpen a VisionPro persistence (.vpp) file that contains a set of saved properties for a LineMax tool. VisionPro reports an error if you try to open a .vpp file for another tool type.
SaveSave the current properties of the LineMax tool to a VisionPro persistence (.vpp) file. The edit control allows you to choose between saving the vision tool with or without its image buffers and tool results.
Save AsSave the current properties of the vision tool to a new VisionPro persistence (.vpp) file.

Reset

Reset the vision tool to its default state.

This tool gives you a choice between resetting to the default-constructed state, which is appropriate when you are using it in a Visual Studio.NET application, and its template-initialized state, which is appropriate for QuickBuild applications.

Image Mask EditorOpen the Image Mask Editor for creating a mask to add to the training image
Show ToolTipsEnable or disable the display of tooltips for individual items in the edit control.
HelpOpen this VisionPro online help file.
Edge Extraction Tab

Use the Edge Extraction tab to configure how a LineMax tool detects candidate edge points:

The tab has the following components:

Expected Line Normal

The edit control places an interactive graphic over the Current.InputImage buffer to assist you in specifying the orientation of the line you want to find:

CognexMultiLineFinder_Reference_ExpectedLineNormalGraphic

Be aware this is not the search region for locating line segments, which you can configure on the Region tab.

Click on the graphic to enable sizing and rotation handles and use it to specify the expected orientation of the line segments you want to locate. See the following examples for how to use the graphic:

CognexMultiLineFinder_Reference_HowToUseGraphics

As you use the graphic be aware of the following:

  • The graphic does not designate a specific region to search for candidate edge points.

    By default the tool searches a CogRectangleAffine for candidate edge points in the direction you specify. Use the Region tab to specify a limited region to search for edge points as your vision application requires. Use a Fixture tool to compensate for how the search region must be reoriented in successive runtime images.

  • The graphic does not specify the polarity of the edge points to search for.

    If you specify a polarity that is not available along the search direction, the tool will not find candidate edge points.

CognexMultiLineFinder_Reference_AreaControl

Edge Point Extraction

The following parameters determine how a CogLineMaxTool detects edge points in the input image:

ParameterDescription

Gradient Kernel Size in Pixels

The tool uses this value to analyze the runtime image and generate a set of gradient vectors representing edge information.

Use a small value when the features of interest in your images display sharp edges, where the transition between light and dark pixels occurs over a short distance. Increase this value for smoother edges in your images.

Projection Length in Pixels

This value determines the number of areas used for gradient field projection. A small value allows the tool to analyze the image with finer granularity than a larger value, but might require more time for the tool to execute. A larger value can improve the execution speed of the tool but might not detect the edges you want the tool to locate.

In general, use a value at least as large as your setting for Gradient Kernel Size in Pixels, but it can be set higher if the tool continues to locate the desired edge points.

Contrast Threshold

Specify the minimum contrast for an edge to be considered a candidate edge for the feature you want to locate. Increase this value to locate edges of stark contrast and ignore edges where the transition between light and dark pixels is not as prominent, or lower this value when the contrast in the edges you want to locate in your images is small.

The contrast of an edge is the absolute difference in average pixel values across the edge, in the range 0 through 255. Only edges with contrast greater than the value you specify are considered by the tool. For example, setting this value to 10 rejects edge points with a contrast below 10 pixel values.

Normalized Contrast ThresholdRaise the value of this parameter to discard false edge points in bright areas of your image. Be aware that setting it to 1 discards all edge points, making the tool effectively nonfunctional.
Line Fitting Tab

Use the Line Fitting tab to configure how the tool locates lines from candidate edge points:

The tab has the following components:

Edge Constraints

Use the following parameters:

ParameterDescription
PolarityThe polarity of the edge points to include in the line.
Angle ToleranceThe maximum allowable angle difference between an edge point gradient direction and then normal to the fit line. Increasing this value allows the tool to consider more edge points as inliers, changing the location of the found line segment.
Distance ToleranceThe maximum allowable distance between an inlier and a fitted line. As you increase the edge distance tolerance, you allow the tool to consider more edge points as inliers and change the location of the found line.
Line Segment Constraints

Configure the following limitations:

ParameterDescription

Max Num Lines

The maximum number of lines you want the tool to locate. Be aware the edit control supports this parameter only when your VisionPro installation includes the VisionPro.LineMaxMulti license. See the topic Using VisionPro Security Keys for details on VisionPro security.

Set this value to 0 to prevent the tool from returning any line results but still generate a set of outliers for use in your vision application.

Angle Tolerance

The amount of rotation a found line segment can differ from the expected angle that you specify.

A low value forces the tool to locate line segments that are more parallel with the gradient search direction.

Coverage Threshold

The minimum acceptable ratio of inliers to the maximum possible number of inliers, or the minimum proportion of edge features along the line segment. For example, specifying a value of 0.5 allows the tool to locate a line segment even though edge points were not detected over 50% of the line.

Use Coverage Threshold and Length Threshold simultaneously to meet your line fitting requirements.

Be aware that specifying a value of 1.0 forces the tool to locate a line segment only when there are no gaps where no inliers were found.

Length ThresholdSet the minimum acceptable length of a found line segment.
Fitting Algorithm

Choose either of the following algorithms for fitting edge points to lines:

ParameterDescription
Exhaustive ModeAll edge point combinations are evaluated for line fitting.

RANSAC Mode

The Random Sample Consensus method (RANSAC): An algorithm for robust fitting of edge points in the presence of many edge point candidates.

The value for Assurance affects the likelihood that the best edge points will be selected for line fitting.

Choose a Timeout value to specify the maximum execution time (msec) allowed to locate the number of requested line segments. If the tool has not finished by the end of the timeout period, it will stop and throw an exception.

Region Tab

Use the Region tab to define the the area of the input image where the tool searches for edge points.

ParameterDescription

RegionMode

Defines the bounding box for the region.

  • Pixel Aligned Bounding Box encloses the defined region within a rectangle. This means that the portions of the image that are outside the defined region but within the bounding rectangle are included.
  • Pixel Aligned Bounding Box Adjust Mask encloses the defined region within a rectangle, but masks out the image portions that are outside the region but inside the enclosing rectangle. The result is that the defined region is closer to what you specify.
RegionThe shape of the search region. By default the tool uses a CogRectangleAffine. Selecting "None=Use entire image" means that the entire Current.InputImage becomes the search region. The set of region-defining parameters depends on the selected Region Shape.
SelectedSpaceNameThe coordinate space in which the search region is interpreted. For more information, see Coordinate Space Names.
FitToImageCenters the search region within Current.InputImage.
Graphics Tab

Use the Graphics tab to control which graphics the tool displays.

ParameterDescription
Inputs
  • Show Expected Line Normal displays the graphics representing the line orientation and the normal to that orientation over the input image.
  • Show Input Image Mask displays any input image mask over the input image. See the topic Using a LineMax Tool for information on using an image mask.
Results
  • Show Inliers: Show the edge points used to fit each line segment in the LastRun.InputImage.
  • Show Found Line: Show the line corresponding to the fitted edge points in the LastRun.InputImage.
  • Show Found Line Segment: Show the line segment that fits the fitted edge points in the LastRun.InputImage.

Diagnostics

Show Input Image: Determine whether or not the input image is recorded as part of the diagnostic record, and whether the image is copied to the record or saved in the record as a reference.

  • Show Region: Dispay the region of interest in the LastRun.InputImage.
  • Show Diagnostic Input Image Mask: Show a graphic representing the run-time mask, if you supplied one. The graphic is shown on the LastRun.InputImage.
  • Show Outliers: Show all edge points that were not used to fit any line segments.
Results Tab

The tool returns the following information about found line segments:

  • The (x,y) location, in coordinates of the selected space, for the start and end of the fitted line segment, including its NormalAngle
  • The number of inliers (Inliers) and the proportion of inliers (Coverage) contributing to this line segment
  • Its polarity (Polarity), intensity (Intensity) and amount of contrast (Contrast)
  • A residual RMS fit error (RMSError), relative to the selected space of the input image, from the contributing inliers
  • A MaxError reporting the distance of the farthest inlier from the line.

If you set the Max Num Lines parameter to 0, the tool returns no line segments but still generates information about edge results with outliers for use in your vision application through the CogLineMaxTool API.