F_VN_LocateEdgeExp2

F_VN_LocateEdgeExp2 1:

Locate the points of the first occuring edge inside a specified search window with subpixel accuracy. (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_LocateEdgeExp2 : HRESULT
VAR_INPUT
    ipSrcImage           : ITcVnImage;
    ipEdgePoints         : Reference To ITcVnContainer;
END_VAR
VAR_IN_OUT
    aStartPoint          : TcVnPoint2_REAL;
    aEndPoint            : TcVnPoint2_REAL;
END_VAR
VAR_INPUT
    eEdgeDirection       : ETcVnEdgeDirection;
    fMinStrength         : REAL;
    nSearchLines         : UDINT;
    fSearchLineDist      : REAL;
    nMaxThickness        : UDINT;
    nSubpixelsIterations : UDINT;
    fApproxPrecision     : REAL;
    eAlgorithm           : ETcVnEdgeDetectionAlgorithm;
    fRangeCutoffFactor   : REAL;
    ipEdgeStrengths      : Reference To ITcVnContainer;
    hrPrev               : HRESULT;
END_VAR
VAR_OUTPUT
    fAvgStrength         : REAL;
END_VAR

 Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (1 channel)

ipEdgePoints

Reference To ITcVnContainer

Returns the detected edge points (ContainerType_Vector_TcVnPoint2_REAL)

eEdgeDirection

ETcVnEdgeDirection

Specification of the edge direction 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

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

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.

ipEdgeStrengths

Reference To ITcVnContainer

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

hrPrev

HRESULT

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

 In/Outputs

Name

Type

Description

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

 Outputs

Name

Type

Description

fAvgStrength

REAL

Returns the average strength of the detected edge

 Return value

HRESULT

Weiterführende Informationen

Die Funktion F_VN_LocateEdgeExp2 ist die Expert-Variante von F_VN_LocateEdge. Sie enthält zusätzliche Parameter.

Parameter

Eingangsbild

Das Eingangsbild ipSrcImage muss ein 1-kanaliges Grauwertbild sein.

Lokalisierte Punkte (Rückgabewert)

Der Container ipEdgePoints gibt die lokalisierten Punkte der linearen Kante zurück.

Das Suchfenster

Zunächst einmal muss ein Suchfenster definiert werden, um festzulegen wo und in welcher Richtung nach einer Kante gesucht werden soll. Dies geschieht mit den Parametern aStartPoint, aEndPoint und nSearchLines. Das Suchfenster ergibt sich aus der Suchlinie von aStartPoint nach aEndPoint und parallel dazu (nSearchLines - 1) / 2 Suchlinien in jede Richtung, mit jeweils 1 Pixel Abstand. Somit definiert nSearchLines die Anzahl der Suchlinien und muss immer einen ungeraden Wert haben.

F_VN_LocateEdgeExp2 2:Abb.15: S: StartPoint, E: EndPoint, W: WindowWidth

Kantenstärke (Rückgabewert)

Der Rückgabewert fAvgStrength zeigt den tatsächlichen Kontrast der lokalisierten Kante (gemittelt über alle Suchlinien) an.

Parameter zur Kantenlokalisierung

Die restlichen Parameter sind ausführlich im Kapitel Kantenlokalisierung erklärt.

Kantenstärken (Rückgabewert)

Die erkannten Kantenstärken der einzelnen Suchlinien werden über ipEdgeStrengths in einem Container vom Typ ContainerType_Vector_REAL zurückgegeben. Dieser Parameter ist optional und kann auf 0 gesetzt werden, wenn er nicht benötigt wird.

Anwendung

Die Lokalisierung einer linearen Kante mit Expert-Parametern sieht z. B. so aus:

hr := F_VN_LocateEdgeExp2(
    ipSrcImage              := ipImageIn,
    ipEdgePoints            := ipEdgePoints,
    aStartPoint             := aStartPoint,
    aEndPoint               := aEndPoint,
    eEdgeDirection          := eDirection,
    fMinStrength            := fMinStrength,
    nSearchLines            := nSearchLines,
    fSearchLineDist         := fSearchLineDist,
    nMaxThickness           := nMaxThickness,
    nSubpixelsIterations    := nSubpixIter,
    fApproxPrecision        := 0.001,
    eAlgorithm              := eAlgorithm,
    fRangeCutoffFactor      := 0.135,
    ipEdgeStrengths         := ipEdgeStrengths,

    hrPrev                  := hr,
    fAvgStrength            => fAvgStrength);

Beispiele

Verwandte Funktionen

Required License

TC3 Vision Metrology 2D

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.59 or later

PC or CX (x64) with min. PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision