F_VN_LocateEdge

F_VN_LocateEdge 1:

Locate the points of the first occuring edge inside a specified search window, using an interpolation method.
Can use available TwinCAT Job Tasks for executing parallel code regions.
Can return partial results when canceled by Watchdog.

Syntax

Definition:

FUNCTION F_VN_LocateEdge : HRESULT
VAR_INPUT
    ipSrcImage     : ITcVnImage;
    ipEdgePoints   : Reference To ITcVnContainer;
END_VAR
VAR_IN_OUT
    aStartPoint    : TcVnPoint2_REAL;
    aEndPoint      : TcVnPoint2_REAL;
END_VAR
VAR_INPUT
    eEdgeDirection : ETcVnEdgeDirection;
    fMinStrength   : REAL;
    nSearchLines   : UDINT;
    hrPrev         : HRESULT;
END_VAR
VAR_OUTPUT
    fAvgStrength   : REAL;
END_VAR

F_VN_LocateEdge 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (1 channel)

ipEdgePoints

Reference To ITcVnContainer

Returns the detected edge points (ContainerType_Vector_TcVnPoint2_REAL)

eEdgeDirection

ETcVnEdgeDirection

Specification of the edge direction to search 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

hrPrev

HRESULT

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

F_VN_LocateEdge 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_LocateEdge 4: Outputs

Name

Type

Description

fAvgStrength

REAL

Returns the average strength of the detected edge

F_VN_LocateEdge 5: Return value

HRESULT

Further information

The function F_VN_LocateEdge localizes an edge in a defined search window.

Parameter

Input image

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

Localized points (Return value)

The container ipEdgePoints returns the localized points of the linear edge.

The search window

First, a search window has to be defined to determine where and in which direction to search for an edge. This is done with the parameters aStartPoint, aEndPoint and nSearchLines. The search window results from the search line from aStartPoint to aEndPoint and parallel to it (nSearchLines - 1) / 2 search lines in each direction, each with 1 pixel distance. Thus nSearchLines defines the number of search lines and must always have an odd value.

F_VN_LocateEdge 6:
S: StartPoint, E: EndPoint, W: WindowWidth

Edge strength (Return value)

The return value fAvgStrength displays the actual contrast of the localized edge (averaged over all search lines).

Parameters for edge localization

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

Expert parameters

The expert version F_VN_LocateEdgeExp contains additional parameters.

Application

The localization of a linear edge looks like this, for example:

hr := F_VN_LocateEdge(
    ipSrcImage              :=  ipImageIn,
    ipEdgePoints            :=  ipEdgePoints,
    aStartPoint             :=  aStartPoint,
    aEndPoint               :=  aEndPoint,
    eEdgeDirection          :=  eDirection,
    fMinStrength            :=  fMinStrength,
    nSearchLines            :=  nSearchLines,
    hrPrev                  :=  hr,
    fAvgStrength            =>  fAvgStrength
);

The localized edge points can be visualized with the function F_VN_DrawContours.

F_VN_DrawContours(ipEdgePoints, -1, 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