F_VN_MeasureEdgeDistanceExp2

F_VN_MeasureEdgeDistanceExp2 1:

Measure the distance between 2 parallel edges. (expert function)
Can use available TwinCAT Job Tasks for executing parallel code regions.
Can return partial results when canceled by Watchdog.

Syntax

Definition:

FUNCTION F_VN_MeasureEdgeDistanceExp2 : HRESULT
VAR_INPUT
    ipSrcImage             : ITcVnImage;
END_VAR
VAR_IN_OUT
    fAvgDistance           : REAL;
    aStartPoint            : TcVnPoint2_REAL;
    aEndPoint              : TcVnPoint2_REAL;
END_VAR
VAR_INPUT
    eEdgeDirection         : ETcVnEdgeDirection;
    fMinStrength           : REAL;
    nSearchLines           : UDINT;
    fSearchLineDist        : REAL;
    nMaxThickness          : UDINT;
    bInvertSearchDirection : BOOL;
    fSearchGap             : REAL;
    nSubpixelsIterations   : UDINT;
    fApproxPrecision       : REAL;
    eAlgorithm             : ETcVnEdgeDetectionAlgorithm;
    ipEdgePoints1          : Reference To ITcVnContainer;
    ipEdgePoints2          : Reference To ITcVnContainer;
    ipDistances            : Reference To ITcVnContainer;
    fRangeCutoffFactor     : REAL;
    hrPrev                 : HRESULT;
END_VAR

 Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (1 channel)

eEdgeDirection

ETcVnEdgeDirection

Specification of the edge direction from aStartPoint to aEndPoint to search for

fMinStrength

REAL

Specification of the minimum strength (intensity difference) of the edge to search for

nSearchLines

UDINT

Width of the search window, i.e. the number of search lines (1, 3, 5, 7, ...), centered around the line specified by aStartPoint and aEndPoint

fSearchLineDist

REAL

Distance between the search lines in pixels (> 0)

nMaxThickness

UDINT

Specification of the maximum thickness of the edge to search for, which means fMinStrength must be reached within nMaxThickness pixels

bInvertSearchDirection

BOOL

If true, the search starts from the center point between aStartPoint and aEndPoint in both directions

fSearchGap

REAL

Optional width of a gap (>= 0, centered between aStartPoint and aEndPoint), that is neglected for searching edges (can reduce execution time). The 2 edges to search for must be on different sides of the gap.

nSubpixelsIterations

UDINT

Specifies the number of subpixels (for INTERPOLATION, 10 - 20 usually is sufficient) or maximum number of iterations for optimizing the parameters (for APPROX_ERF and APPROX_GAUSSIAN, 50 - 100 usually is sufficient)

fApproxPrecision

REAL

Specifies the approximation precision for APPROX_ERF and APPROX_GAUSSIAN (0.001 usually is sufficient, unused for INTERPOLATION)

eAlgorithm

ETcVnEdgeDetectionAlgorithm

Selection of the edge detection algorithm

ipEdgePoints1

Reference To ITcVnContainer

Returns the detected edge points of the edge near aStartPoint (optional, set to 0 if not required; ContainerType_Vector_TcVnPoint2_REAL)

ipEdgePoints2

Reference To ITcVnContainer

Returns the detected edge points of the edge near aEndPoint (optional, set to 0 if not required; ContainerType_Vector_TcVnPoint2_REAL)

ipDistances

Reference To ITcVnContainer

Returns the distances between the detected edge points (optional, set to 0 if not required; ContainerType_Vector_REAL)

fRangeCutoffFactor

REAL

Relative edge strength factor to cut off the range of pixels used for approximation. Negative numbers are valid to include noise, i.e. intensity differences in the other direction. At most nMaxThickness pixels are used in each direction.

hrPrev

HRESULT

HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.)

 In/Outputs

Name

Type

Description

fAvgDistance

REAL

Returns the average distance between the detected edges

aStartPoint

TcVnPoint2_REAL

Position from which to start the search process (in the direction of aEndPoint)

aEndPoint

TcVnPoint2_REAL

Position where the search process ends

 Return value

HRESULT

Further information

The F_VN_MeasureEdgeDistanceExp2 function is the expert version of F_VN_MeasureEdgeDistance. It contains additional parameters.

Parameter

Input image

The ipSrcImage input image must be a 1-channel grayscale image.

Average distance (Return value)

The fAvgDistance parameter returns the average distance between the two localized edges.

The search window

First, a search window has to be defined to determine where and in which direction to search for an edge. This is done using the aStartPoint, aEndPoint and nSearchLines parameters. The search window results from the search line from aStartPoint to aEndPoint and parallel to it (nSearchLines - 1) / 2 search lines in each direction, each with 1 pixel distance. Thus nSearchLines defines the number of search lines and must always have an odd value.

F_VN_MeasureEdgeDistanceExp2 2:Fig.15: S: StartPoint, E: EndPoint, W: WindowWidth

Localized edge points (Expert, return value)

The ipEdgePoints1 and ipEdgePoints2 containers return the exact points that were localized on the basis of each search line. If not needed, the 0 value can be transferred instead of an interface pointer.

Measured distances (Expert, return value)

The ipDistances container returns all measured distances between opposite points. If not needed, the 0 value can be transferred instead of an interface pointer.

Search gap (Expert)

With fSearchGap you can specify an area in the middle of the defined search line that is omitted or skipped during the search. This can reduce the execution time.

Parameters for edge localization

The remaining parameters are explained in detail in the chapter Edge localization.

Application

The measurement of an edge distance with expert parameters looks like this, for example:

hr := F_VN_MeasureEdgeDistanceExp2(
    ipSrcImage              := ipImageIn,
    fAvgDistance            := fAvgDistance,
    aStartPoint             := aStartPoint,
    aEndPoint               := aEndPoint,
    eEdgeDirection          := TCVN_ED_LIGHT_TO_DARK,
    fMinStrength            := fMinStrength,
    nSearchLines            := nSearchLines,
    fSearchLineDist         := 3,
    nMaxThickness           := 7,
    bInvertSearchDirection  := TRUE,
    fSearchGap              := 100,
    nSubpixelsIterations    := nSubpixIter,
    fApproxPrecision        := 0.001,
    eAlgorithm              := eAlgorithm,
    ipEdgePoints1           := ipEdgePoints1,
    ipEdgePoints2           := ipEdgePoints2,
    ipDistances             := ipDistances,
    fRangeCutoffFactor      := 0.135,
    hrPrev                  := hr);

Related functions

Required License

TC3 Vision Metrology 2D

System Requirements