F_VN_LocateEllipseExp

F_VN_LocateEllipseExp 1:

Locate an ellipse. (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_LocateEllipseExp : HRESULT
VAR_INPUT
    ipSrcImage             : ITcVnImage;
END_VAR
VAR_IN_OUT
    stEllipse              : TcVnRotatedRectangle;
    aCenter                : TcVnPoint2_REAL;
END_VAR
VAR_INPUT
    fSearchRadius          : REAL;
    eEdgeDirection         : ETcVnEdgeDirection;
    fMinStrength           : REAL;
    nMaxThickness          : UDINT;
    bInvertSearchDirection : BOOL;
    fMinSearchRadius       : REAL;
    nSubpixelsIterations   : UDINT;
    nSearchLines           : UDINT;
    fApproxPrecision       : REAL;
    eAlgorithm             : ETcVnEdgeDetectionAlgorithm;
    ipContourPoints        : Reference To ITcVnContainer;
    hrPrev                 : HRESULT;
END_VAR

F_VN_LocateEllipseExp 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (1 channel)

fSearchRadius

REAL

Radius around aCenter to search for edges

eEdgeDirection

ETcVnEdgeDirection

Specification of the edge direction to search for (from center to outside ellipse or other way round, if bInvertSearchDirection is true)

fMinStrength

REAL

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

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 outside the ellipse in direction of the center

fMinSearchRadius

REAL

Radius around aCenter to skip before starting to search for edges (e.g. to save time or if the center contains edges that should be ignored)

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)

nSearchLines

UDINT

Specifies the amount of search lines, which are equally distributed in all directions (must be >= 8 and a multiple of 4)

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

ipContourPoints

Reference To ITcVnContainer

Returns the subpixel accurate ellipse contour (optional, set to 0 if not required; ContainerType_Vector_TcVnPoint2_REAL; Non-zero interface pointers are reused.)

hrPrev

HRESULT

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

F_VN_LocateEllipseExp 3: In/Outputs

Name

Type

Description

stEllipse

TcVnRotatedRectangle

Returns the detected ellipse

aCenter

TcVnPoint2_REAL

The expected ellipse center

F_VN_LocateEllipseExp 4: Return value

HRESULT

Weiterführende Informationen

Die Funktion F_VN_LocateEllipseExp ist die Expert-Variante von F_VN_LocateEllipse.

Parameter

Eingangsbild

Das Eingangsbild ipSrcImage muss ein 1-kanaliges Grauwertbild sein.

Ellipse (Rückgabewert)

Der Parameter stEllipse liefert die lokalisierte Ellipse als Struktur vom Typ TcVnRotatedRectangle zurück (Mittelpunkt, Größe und Winkel).

Suchkreis

Der kreisförmige Suchbereich wird über den erwarteten Mittelpunkt aCenter und sowie einen Suchradius fSearchRadius definiert. Der Suchradius sollte etwas größer als der erwartete Ellipsenradius festgelegt werden, um die Ellipse sicher zu lokalisieren.

Lokalisierte Punkte (Expert, Rückgabewert)

Der Container ipContourPoints gibt die lokalisierten Punkte zurück.

Wenn die Rückgabe der Kantenpunkte nicht benötigt wird, kann der Parameter auf 0 gesetzt werden.

Parameter zur Kantenlokalisierung

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

Anwendung

Die Lokalisierung und Vermessung einer Ellipse mit Expert-Parametern sieht z. B: so aus:

hr := F_VN_LocateEllipseExp(
    ipSrcImage              :=  ipImageIn,
    stEllipse               :=  stEllipse,
    aCenterPoint            :=  aGuessedCenter,
    fSearchRadius           :=  (fGuessedRadius + 15), // increase search radius to make sure ellipse is found!
    eEdgeDirection          :=  TCVN_ED_LIGHT_TO_DARK,
    fMinStrength            :=  fMinStrength,
    nMaxThickness           :=  7,
    bInvertSearchDirection  :=  TRUE,
    fMinSearchRadius        :=  fMinRadius,
    nSubpixelsIterations    :=  nSubpixIter,
    nSearchLines            :=  nSearchLines,
    fApproxPrecision        :=  0.0001,
    eAlgorithm              :=  eAlgorithm,
    ipContourPoints         :=  ipContourPoints,

    hrPrev                  :=  hr
);

Die lokalisierten Punkte der Ellipse können mit der Funktion F_VN_DrawContours visualisiert werden:

hr := F_VN_DrawContours(ipContourPoints, -1, ipImageRes, aColorGreen, 5, hr);

Beispiele

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