CountAndMeasureObjects Method

NI Vision for Visual Basic

CountAndMeasureObjects Method

Syntax

CWMachineVision.CountAndMeasureObjects SourceImage, ObjectsReport [, SearchRotatedRectangle] [, CountAndMeasureObjectsOptions] [, CoordinateTransformation]

Return Type

Long

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

Purpose

Locates, counts, and measures objects in a rectangular search area. This method uses a threshold on the pixel intensities to segment the objects from their background.

Remarks

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

Optional filters give the capability to ignore the objects smaller or larger than given sizes. Other options allow rejecting the objects touching the borders of the search area and ignoring the holes that the segmentation process may create in the objects. The segmented objects are then located and measured. CountAndMeasureObjects can overlay on the image returned the position of the search area, the centers and bounding rectangles of the objects detected.

Parameters

SourceImage As CWIMAQImage

The input image.

ObjectsReport As CWMVObjectsReport

On return, a report containing information about each object found in the image.

SearchRotatedRectangle As Variant

[Optional] A CWIMAQRotatedRectangle object that specifies the region within an image to search. If you do not supply this parameter, the entire image is examined.

CountAndMeasureObjectsOptions As Variant

[Optional] A CWMVCountAndMeasureObjectsOptions object that contains additional options for this function. If not supplied, the defaults are used.

CoordinateTransformation As Variant

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

Example

Private Sub Run_Click()
    'Input objects
    Dim SearchRectangle As New CWIMAQRotatedRectangle
    Dim Options As New CWMVCountAndMeasureObjectsOptions
    Dim Transformation As New CWMVCoordinateTransformation
    
    'Output objects
    Dim ObjectsReport As New CWMVObjectsReport
    
    'Get the currently selected rectangle or rotated rectangle from the viewer. If nothing is
    'selected, get a rectangle representing the entire image.
    CWMachineVision1.GetSelectedRotatedRectFromViewer CWIMAQViewer1, SearchRectangle, False
                                                           
    ' Find objects on the Viewer image in the selected rectangle
    CWMachineVision1.CountAndMeasureObjects CWIMAQViewer1.Image, ObjectsReport, _
                                            SearchRectangle, Options, Transformation
End Sub

See Also

CWIMAQVision.Threshold

GetSelectedRotatedRectFromViewer

CWIMAQRotatedRectangle

CWMVCountAndMeasureObjectsOptions

CWIMAQVision.ParticleReport