MeasureMinimumDistance Method

NI Vision for Visual Basic

MeasureMinimumDistance Method

Syntax

CWMachineVision.MeasureMinimumDistance 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 the horizontal or vertical direction, from the center of the search area towards the sides 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 in the right half of the search area. A second vertical hit-line to the object is calculated through the right-most edge in the left half of the search area. If the MeasurementAxis is vertical, a horizontal hit-line to the object is calculated through the upper-most edge detected in the lower half of the search area. A second horizontal hit-line to the object is calculated through the lower-most edge in the upper half of the search area. 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 left or top nearest edge point to the center line of the input rotated rectangle, depending on the MeasurementAxis.

LastEdgePoint As Variant

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

Example

Private Sub Run_Click()
    'Inputs to MeasureMinimumDistance
    Dim SearchArea As New CWIMAQRotatedRectangle
    Dim Options As New CWMVCommonEdgeOptions
    Dim Transformation As New CWMVCoordinateTransformation
    
    'Outputs of MeasureMinimumDistance
    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 minimum distance in the horizontal direction
    CWMachineVision1.MeasureMinimumDistance CWIMAQViewer1.Image, SearchArea, cwmvHorizontalAxis, _
                                            Distance, Options, Transformation, FirstEdgePoint, _
                                            LastEdgePoint
    
    'Display the measured distance
    Text1.Text = Distance
End Sub

See Also

CWIMAQVision.Rake

CWMVCommonEdgeOptions

CWIMAQPoints