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 function F_VN_LocateEllipse 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 input image ipSrcImage must be a 1-channel grayscale image.

Ellipse (Return value)

The parameter stEllipse 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 center point aCenter and a search radius fSearchRadius. 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 expert version F_VN_LocateEllipse(Exp) contains additional parameters.

Application

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

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

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,
    hrPrev                  :=  hr
);

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

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

Samples

Related functions

Required License

TC3 Vision Metrology 2D

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.54 or later

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

Tc3_Vision