F_VN_LocateEdgesExp

F_VN_LocateEdgesExp 1:

Locate the points of multiple occuring edges 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_LocateEdgesExp : HRESULT
VAR_INPUT
    ipSrcImage           : ITcVnImage;
    ipEdgePoints         : Reference To ITcVnContainer;
END_VAR
VAR_IN_OUT
    aStartPoint          : TcVnPoint2_REAL;
    aEndPoint            : TcVnPoint2_REAL;
END_VAR
VAR_INPUT
    nNumEdges            : UDINT;
    eEdgeDirection       : ETcVnEdgeDirection;
    bAlternateDirection  : BOOL;
    fMinStrength         : REAL;
    nSearchLines         : UDINT;
    fSearchLineDist      : REAL;
    nMaxThickness        : UDINT;
    nSubpixelsIterations : UDINT;
    fApproxPrecision     : REAL;
    eAlgorithm           : ETcVnEdgeDetectionAlgorithm;
    hrPrev               : HRESULT;
END_VAR
VAR_OUTPUT
    fAvgStrength         : REAL;
END_VAR

F_VN_LocateEdgesExp 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (1 channel)

ipEdgePoints

Reference To ITcVnContainer

Returns the detected edge points (ContainerType_Vector_Vector_TcVnPoint2_REAL)

nNumEdges

UDINT

The (maximum) number of edges to search for

eEdgeDirection

ETcVnEdgeDirection

Specification of the edge direction to search for

bAlternateDirection

BOOL

If true, eEdgeDirection is alternated after each detected edge. Else, only edges with eEdgeDirection are searched 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

hrPrev

HRESULT

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

F_VN_LocateEdgesExp 3: 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

F_VN_LocateEdgesExp 4: Outputs

Name

Type

Description

fAvgStrength

REAL

Returns the average strength of the detected edges

F_VN_LocateEdgesExp 5: Return value

HRESULT

Weiterführende Informationen

Die Funktion F_VN_LocateEdgesExp ist die Expert-Variante von F_VN_LocateEdges. 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 Kanten 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_LocateEdgesExp 6:
S: StartPoint, E: EndPoint, W: WindowWidth

Kantenstärke (Rückgabewert)

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

Parameter zur Kantenlokalisierung

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

Anwendung

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

hr := F_VN_LocateEdgesExp(
    ipSrcImage              :=  ipImageIn,
    ipEdgePoints            :=  ipEdgePoints,
    aStartPoint             :=  aStartPoint,
    aEndPoint               :=  aEndPoint,
    nNumEdges               :=  nNumEdges,
    eEdgeDirection          :=  eDirection,
    bAlternateDirection     :=  bAlternateDirection,
    fMinStrength            :=  fMinStrength,
    nSearchLines            :=  nSearchLines,
    fSearchLineDist         :=  fSearchLineDist
    nMaxThickness           :=  nMaxThickness,
    nSubpixelsIterations    :=  nSubpixIter,
    fApproxPrecision        :=  0.001,
    eAlgorithm              :=  eAlgorithm,
    hrPrev                  :=  hr,
    fAvgStrength            =>  fAvgStrength
);

Verwandte Funktionen

Required License

TC3 Vision Metrology 2D

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1. 4024.44 or later

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

Tc3_Vision