FindCoordTransformUsingRect Method

NI Vision for Visual Basic

FindCoordTransformUsingRect Method

Syntax

CWMachineVision.FindCoordTransformUsingRect SourceImage, SearchRotatedRectangle, MainAxisScanDirection, AxisOrientation, FirstRun, CoordinateTransformation [, CommonEdgeOptions] [, MainAxisLine] [, SecondaryAxisLine]

Return Type

Long

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

Purpose

Computes a transformation based on the position of an object in a search area of an image. The location and orientation of the coordinate system found is used to create the reference coordinate system or to update the measurement coordinate system. The method can overlay, on the image returned, the position of the search area, the search lines, the edges found, and the location and orientation of the coordinate system found.

Remarks

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

This method uses the following algorithm. First it determines the position of the main axis of the coordinate system. It 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, width, and steepness. The method calculates a best-fit line using the points found. This line defines the main axis of the coordinate system. The method then locates the intersection points between a set of parallel search lines, or rake, perpendicular to the main axis and the edge of the object. It calculates a hit-line to the object from the edge closest to the search area detected and perpendicular to the main axis. This line defines the secondary axis of the coordinate system. The intersection between the main axis and secondary axis is the origin of the coordinate system.

Parameters

SourceImage As CWIMAQImage

The input image.

SearchRotatedRectangle As CWIMAQRotatedRectangle

Specifies a rectangular search area.

MainAxisScanDirection As CWIMAQRakeScanDirections

Indicates the direction of the rake that searches for the main axis.

AxisOrientation As CWIMAQAxisOrientations

The scan direction for the secondary axis is rotated 90 degrees from the scan direction of the main axis. AxisOrientation indicates whether the 90 degree angle is determined using a direct or indirect coordinate system.

FirstRun As Boolean

Indicates whether this is the first time that FindCoordTransformUsingPattern is run. If it is, this method uses the coordinate system it finds as the reference and measurement coordinate system. Otherwise, it updates the MeasurementSystem and leaves the ReferenceSystem unchanged.

CoordinateTransformation As CWMVCoordinateTransformation

On return, this parameter contains the reference coordinate system and measurement coordinate system.

CommonEdgeOptions As Variant

[Optional] A CWMVCommonEdgeOptions object defining the parameters of the algorithm and the information that are overlaid to the result image.

MainAxisLine As Variant

[Optional] On return, a CWIMAQLine object specifying the coordinates of the edge corresponding to the MainAxis. The first point is the intersection of the two axis of the coordinate system. The second point is the result of the computation of the intersection of the MainAxis with the SearchArea.

SecondaryAxisLine As Variant

[Optional] On return, a CWIMAQLine object specifying the coordinates of the edge corresponding to the SecondaryAxis. The first point is the intersection of the two axis of the coordinate system. The second point is the result of the computation of the intersection of the SecondaryAxis with the rectangular SearchArea.

Example

'This example illustrates how to call CWMachineVision.FindCoordTransformUsingRect
'To see how CWMachineVision.FindCoordTransform methods are used, see
'Battery Clamp Inspection Example and Fuse Inspection Example.

'Required inputs of CWMachineVision.FindCoordTransformUsingRect
Dim Image As New CWIMAQImage
Dim SearchArea As New CWIMAQRotatedRectangle
Dim ScanDirection As CWIMAQRakeScanDirections
Dim AxisOrientation As CWIMAQAxisOrientations
Dim FirstRun As Boolean

'Optional inputs of CWMachineVision.FindCoordTransformUsingRect
Dim CommonEdgeOptions As New CWMVCommonEdgeOptions

'Required return values of CWMachineVision.FindCoordTransformUsingRect
Dim Transformation As New CWMVCoordinateTransformation

'Optional return values of CWMachineVision.FindCoordTransformUsingRect
Dim MainAxisLine As New CWIMAQLine
Dim SecondaryAxisLine As New CWIMAQLine

'Set FirstRun to True to have CWMachineVision.FindCoordTransformUsingRect build a new coordinate
'transformation. Set FirstRun to False to have CWMachineVision.FindCoordTransformUsingRect
'update an existing coordinate transformation
FirstRun = True

CWMachineVision1.FindCoordTransformUsingRect Image, SearchArea, ScanDirection, AxisOrientation, _
                                             FirstRun, Transformation, CommonEdgeOptions, _
                                             MainAxisLine, SecondaryAxisLine

See Also

FindCoordTransformUsingPattern

FindCoordTransformUsingTwoRects

CWIMAQVision.Rake

TransformRegions

CWIMAQRotatedRectangle

CWMVCommonEdgeOptions

CWIMAQLine