F_VN_LocateEllipse

F_VN_LocateEllipse 1:

Locate an ellipse, using an interpolation method for locating the edges.
Can use available TwinCAT Job Tasks for executing parallel code regions.
Can return partial results when canceled by Watchdog.

Syntax

Definition:

FUNCTION F_VN_LocateEllipse : 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;
    hrPrev         : HRESULT;
END_VAR

F_VN_LocateEllipse 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (1 channel)

fSearchRadius

REAL

Radius around aCenter to search for edges (aCenter + fSearchRadius in all directions must be inside image borders!)

eEdgeDirection

ETcVnEdgeDirection

Specification of the edge direction to search for (from center to outside ellipse)

fMinStrength

REAL

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

hrPrev

HRESULT

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

F_VN_LocateEllipse 3: In/Outputs

Name

Type

Description

stEllipse

TcVnRotatedRectangle

Returns the detected ellipse

aCenter

TcVnPoint2_REAL

The expected ellipse center

F_VN_LocateEllipse 4: Return value

HRESULT

Further information

The F_VN_LocateEllipse function localizes and measures an ellipse. It is based on the edge localization and uses normal parameters. It returns the localized ellipse as a structure of the type TcVnRotatedRectangle (center point, size and angle).

Parameter

Input image

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

Ellipse (Return value)

The stEllipse parameter returns the localized ellipse as structure of the type TcVnRotatedRectangle (center point, size and angle).

Search circle

The circular search area is defined via the expected aCenter center point and a fSearchRadius search radius. The search radius should be set somewhat larger than the expected ellipse radius in order to securely localize the ellipse.

Parameters for edge localization

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

Expert parameters

The F_VN_LocateEllipseExp expert version contains additional parameters.

Application

The localization and measurement of an ellipse with an estimated center point of [360, 240] and a radius of 100px looks like this, for example:

VAR
    aGuessedCenter      :   TcVnPoint2_REAL := [360, 240];
    fGuessedRadius      :   REAL := 100;
END_VAR

hr := F_VN_LocateEllipse(
    ipSrcImage          := ipImageIn,
    stEllipse           := stEllipse,
    aCenter             := aGuessedCenter,
    fSearchRadius       := (fGuessedRadius + 15), // increase search radius to make sure ellipse is found!
    eEdgeDirection      := TCVN_ED_LIGHT_TO_DARK,
    fMinStrength        := fMinStrength,
    hrPrev              := hr);

The properties of the localized ellipse can then be accessed via the stEllipse.aCenter, stEllipse.stSize and stEllipse.fAngle variables. In addition, the ellipse can be visualized with the F_VN_DrawEllipse function:

hr := F_VN_DrawEllipse(stEllipse, ipImageRes, aColorGreen, 5, hr);

Samples

Related functions

Required License

TC3 Vision Metrology 2D

System Requirements