ConvertPixelToRealWorldCoordinates Method

NI Vision for Visual Basic

ConvertPixelToRealWorldCoordinates Method

Syntax

CWIMAQVision.ConvertPixelToRealWorldCoordinates CalibratedImage, PixelCoordinates, RealWorldCoordinatesReport

Return Type

Long

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

Purpose

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

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.

PixelCoordinates As CWIMAQPoints

The pixel coordinates to transform.

RealWorldCoordinatesReport As CWIMAQCoordinatesReport

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

Example

Private Sub Run_Click()
    Dim brokenLine As CWIMAQBrokenline
    Dim pixelCoordinates As 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
    
    ' Calibrate the image in Viewer1
    simpleCalibrationOptions.GridDescriptor.XStep = 10
    simpleCalibrationOptions.GridDescriptor.YStep = 10
    simpleCalibrationOptions.GridDescriptor.Unit = cwimaqCalUnitMeter
    
    CWIMAQVision1.SetSimpleCalibration CWIMAQViewer1.Image, _
                                       simpleCalibrationOptions
    
    ' Find the real-world coordinates corresponding to the coordinates of a
    ' broken line region selected on the image.
    Set brokenLine = CWIMAQViewer1.Regions(1)
    Set pixelCoordinates = brokenLine.Points
    CWIMAQVision1.ConvertPixelToRealWorldCoordinates CWIMAQViewer1.Image, _
                                                     pixelCoordinates, _
                                                     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 pixelCoordinates(j).X - 4, _
                            pixelCoordinates(j).Y - 4, 8, 8
            point.Initialize pixelCoordinates(j).X, pixelCoordinates(j).Y - 8
            text = "(" & report.Coordinates(j).X & "," & _
                         report.Coordinates(j).Y & ")"
            CWIMAQViewer1.Image.Overlays(1).DrawOval oval, cwimaqOverlayModePaint, vbRed
            CWIMAQViewer1.Image.Overlays(1).DrawText point, textOptions, text
        End If
    Next
End Sub

See Also

LearnCalibrationGrid

LearnCalibrationPoints

SetSimpleCalibration

SetCalibrationInformation