FindStraightEdge Method

NI Vision for Visual Basic

FindStraightEdge Method

Syntax

CWMachineVision.FindStraightEdge SourceImage, SearchRotatedRectangle, ScanDirection, FindStraightEdgeReport [, CommonEdgeOptions] [, CoordinateTransformation]

Return Type

Long

On success, this method returns 0. On failure, this function returns a negative number.

Purpose

Locates a straight edge in a search area. This method locates the intersection points between a set of parallel search lines, or rake, and the edge of an object. The intersection points are determined based on their contrast and slope.

Remarks

Use this method with U8, I16, and SGL images.

A best-fit line is calculated through the points found. The method returns the coordinates of the edge found as well as its straightness. FindStraightEdge can overlay on the image returned: the position of the search area, the search lines, the edges used in the best-fit line calculation, and the result line.

Parameters

SourceImage As CWIMAQImage

The input image.

SearchRotatedRectangle As CWIMAQRotatedRectangle

A CWIMAQRotatedRectangle object that specifies the region within an image to search.

ScanDirection As CWIMAQRakeScanDirections

Specifies the direction where the search lines are scanned for edges.

FindStraightEdgeReport As CWMVFindStraightEdgeReport

On return, a report containing information about the edge that was found.

CommonEdgeOptions As Variant

[Optional] A CWMVCommonEdgeOptions object that contains additional options for this function. If not supplied, the defaults are used.

CoordinateTransformation As Variant

[Optional] A CWMVCoordinateTransformation object. If supplied, the input search area is transformed using this parameter.

Example

Private Sub Run_Click()
    'Input objects
    Dim SearchArea As New CWIMAQRotatedRectangle
    Dim Options As New CWMVCommonEdgeOptions
    Dim Transformation As New CWMVCoordinateTransformation
    
    'Output objects
    Dim Report As New CWMVFindStraightEdgeReport
    
    'Get the currently selected rotated rectangle from the viewer. If not supplied,
    'scan the entire image.
    CWMachineVision1.GetSelectedRotatedRectFromViewer CWIMAQViewer1, SearchArea, False
                                                           
    ' Find objects on the Viewer image in the selected rectangle
    CWMachineVision1.FindStraightEdge CWIMAQViewer1.Image, SearchArea, cwimaqScanLeftToRight, _
                                      Report, Options, Transformation
End Sub

See Also

CWIMAQVision.Rake

CWMVCommonEdgeOptions

GetSelectedRotatedRectFromViewer