ConvertRealWorldToPixelCoordinates Method

NI Vision for Visual Basic

ConvertRealWorldToPixelCoordinates Method

Syntax

CWIMAQVision.ConvertRealWorldToPixelCoordinates CalibratedImage, RealWorldCoordinates, PixelCoordinatesReport

Return Type

Long

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

Purpose

Transforms real world coordinates to pixel coordinates, according to the calibration information.

Remarks

Use this method with image types U8, U16, I16, SGL, RGB32 and HSL32. Attach calibration information to this image using CWIMAQVision.LearnCalibrationGrid, CWIMAQVision.LearnCalibrationPoints, CWIMAQVision.SetSimpleCalibration, or CWIMAQVision.SetCalibrationInformation.

Parameters

CalibratedImage As CWIMAQImage

The calibrated image.

RealWorldCoordinates As CWIMAQPoints

The real world coordinates to transform.

PixelCoordinatesReport As CWIMAQCoordinatesReport

On return, a CWIMAQCoordinatesReport containing information about the transformed coordinates.

Example

Private Sub Run_Click()
    Dim realWorldCoordinates As New CWIMAQPoints
    Dim report As New CWIMAQCoordinatesReport
    Dim j
    Dim CoordinatesValid
    Dim simpleCalibrationOptions As New CWIMAQSimpleCalibrationOptions
    Dim textOptions As New CWIMAQTextOptions
    Dim oval As New CWIMAQOval
    Dim point As New CWIMAQPoint
    Dim text As String
    
    realWorldCoordinates.Initialize Array(10, 100), Array(10, 100)
    
    ' Calibrate the image in Viewer1
    simpleCalibrationOptions.GridDescriptor.XStep = 10
    simpleCalibrationOptions.GridDescriptor.YStep = 10
    simpleCalibrationOptions.GridDescriptor.Unit = cwimaqCalUnitMeter
    
    CWIMAQVision1.SetSimpleCalibration CWIMAQViewer1.Image, _
                                       simpleCalibrationOptions
    
    ' Find the pixel coordinates corresponding to the given
    ' real-world coordinates.
    CWIMAQVision1.ConvertRealWorldToPixelCoordinates CWIMAQViewer1.Image, _
                                                     realWorldCoordinates, _
                                                     report
    
    'Initialize the text options
    textOptions.ForeColor = vbWhite
    ' Display the real-world coordinates corresponding to the pixels in the image
    CWIMAQViewer1.Image.Overlays(1).Clear
    CoordinatesValid = report.CoordinatesValid
    For j = 1 To report.Coordinates.Count
        If CoordinatesValid(j - 1) Then
            oval.Initialize report.Coordinates(j).X - 4, _
                            report.Coordinates(j).Y - 4, 8, 8
            point.Initialize report.Coordinates(j).X, report.Coordinates(j).Y - 8
            text = "(" & realWorldCoordinates(j).X & "," & _
                         realWorldCoordinates(j).Y & ")"
            CWIMAQViewer1.Image.Overlays(1).DrawOval oval, cwimaqOverlayModePaint, vbRed
            CWIMAQViewer1.Image.Overlays(1).DrawText point, textOptions, text
        End If
    Next
End Sub