MeasureMaximumDistance Method

NI Vision for Visual Basic

MeasureMaximumDistance Method

Syntax

CWMachineVision.MeasureMaximumDistance SourceImage, SearchArea, MeasurementAxis, Distance [, CommonEdgeOptions] [, CoordinateTransformation] [, FirstEdgePoint] [, LastEdgePoint]

Return Type

Long

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

Purpose

Measures a distance in either the horizontal or vertical direction, from the sides of the search area towards the center of the search area. This method locates edges along a set of parallel search lines, or rake. The edges are determined based on their contrast and slope.

Remarks

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

If the MeasurementAxis is horizontal, a vertical hit-line to the object is calculated through the left-most edge detected. A second vertical hit-line to the object is calculated through the right-most edge. If the MeasurementAxis is vertical, a horizontal hit-line to the object is calculated through the upper-most edge detected. A second horizontal hit-line to the object is calculated through the lower-most edge. In either case, the distance between the two lines found is returned.

This method can overlay on the image returned the position of the search area, the search lines, the edges found, and the result.

Parameters

SourceImage As CWIMAQImage

The input image.

SearchArea As CWIMAQRotatedRectangle

Specifies a rectangular search area.

MeasurementAxis As CWMVAxisDirection

The axis direction in which the measurement is performed.

Distance As Single

On return, the measured distance.

CommonEdgeOptions As Variant

[Optional] A CWMVCommonEdgeOptions object defining the parameters of the algorithm that detects the edge locations and the information that is overlaid on the result image.

CoordinateTransformation As Variant

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

FirstEdgePoint As Variant

[Optional] On return, a CWIMAQPoint object that indicates the nearest edge point to the left or top side of input rotated rectangle, depending on the MeasurementAxis.

LastEdgePoint As Variant

[Optional] On return, a CWIMAQPoint object that indicates the nearest edge point to the right or bottom side of input rotated rectangle, depending on the MeasurementAxis.

Example

Private Sub Run_Click()
    'Inputs to MeasureMaximumDistance
    Dim SearchArea As New CWIMAQRotatedRectangle
    Dim Options As New CWMVCommonEdgeOptions
    Dim Transformation As New CWMVCoordinateTransformation
    
    'Outputs of MeasureMaximumDistance
    Dim Distance As Single
    Dim FirstEdgePoint As New CWIMAQPoint
    Dim LastEdgePoint As New CWIMAQPoint
    
    'Get the search area from the viewer
    CWMachineVision1.GetSelectedRotatedRectFromViewer CWIMAQViewer1, SearchArea
    
    'Measure the maximum distance in the horizontal direction
    CWMachineVision1.MeasureMaximumDistance CWIMAQViewer1.Image, SearchArea, cwmvHorizontalAxis, _
                                            Distance, Options, Transformation, FirstEdgePoint, _
                                            LastEdgePoint
    
    'Display the measured distance
    Text1.Text = Distance
End Sub

Clamp Example
Battery Clamp Inspection Example

See Also

CWIMAQVision.Rake

CWMVCommonEdgeOptions

CWIMAQPoints