F_VN_LocateEllipseExp
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
Inputs
Name |
Type |
Description |
---|---|---|
ipSrcImage |
Source image (1 channel) | |
fSearchRadius |
REAL |
Radius around aCenter to search for edges |
eEdgeDirection |
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 |
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 indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
In/Outputs
Name |
Type |
Description |
---|---|---|
stEllipse |
Returns the detected ellipse | |
aCenter |
The expected ellipse center |
Further information
The function F_VN_LocateEllipseExp
is the expert version of F_VN_LocateEllipse.
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.
Localized points (Expert, return value)
The container ipContourPoints
returns the localized points.
The parameter can be set to 0 if the return of the edge points is not required.
Parameters for edge localization
The remaining parameters are explained in detail in the chapter Edge localization.
Application
The localization and measurement of an ellipse with expert parameters looks like this, for example:
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
);
The localized points of the ellipse can be visualized with the function F_VN_DrawContours.
hr := F_VN_DrawContours(ipContourPoints, -1, ipImageRes, aColorGreen, 5, hr);
Samples
Related functions
- LocateCircularArc for localizing proportional circular arcs
- LocateEdge for localizing linear edges
- LocateEdges for localizing several linear edges
- LocateEllipse for localizing complete ellipses
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 |