BasicParticle Method

NI Vision for Visual Basic

BasicParticle Method

Syntax

CWIMAQVision.BasicParticle SourceImage, BasicReport [, Connectivity8 = True]

Return Type

Long

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

Purpose

Obsolete—Use ParticleReport instead. Detects and returns the area and position of particles in a binary image.

Remarks

This method modifies the source image. If you need the original source image, create a copy of the image using the CWIMAQVision.Copy method before using this method.

Use this method with U8 images.

Parameters

SourceImage As CWIMAQImage

The image containing particles to analyze. A particle consists of pixels whose value is not 0. The image must be binary (a thresholded U8 image) and must have a border size of at least 2. The calculation modifies the border of the image.

BasicReport As CWIMAQBasicParticleReport

On return, a report object filled with a set of measurements about the detected particles.

Connectivity8 As Variant

[Optional] Set this parameter to True to use connectivity-8 to determine whether particles are touching. Set this parameter to False to use connectivity-4 to determine whether particles are touching. For more information about connectivity, refer to the NI Vision Concepts Manual.

This parameter has a default value of True.

Example

Private Sub Run_Click()
    Dim report1 As New CWIMAQBasicParticleReport
    Dim i

    ' Threshold the image in place
    CWIMAQVision1.Threshold CWIMAQViewer1.Image, CWIMAQViewer1.Image, , , , 255

    ' Do particle analysis
    CWIMAQVision1.BasicParticle CWIMAQViewer1.Image, report1

    ' For each particle, display Area and the Bounding Rectangle
    For i = 1 To report1.Count
        Dim Area
        Dim Text As String
        Dim textOptions As New CWIMAQTextOptions
        Dim rotatedRect As CWIMAQRotatedRectangle
        Area = report1(i).Area
        Text = "A: " & CStr(Area)
        CWIMAQViewer1.Image.Overlays(1).DrawRectangle report1(i).BoundingRectangle, cwimaqDrawModeFrame
        textOptions.HorizontalAlignment = cwimaqHorizontalTextAlignmentCenter
        textOptions.Style = cwimaqTextStyleNormal
        textOptions.FontName = "Arial"
        textOptions.Size = 16
        textOptions.ForeColor = vbBlue
        Set rotatedRect = report1(i).BoundingRectangle.MakeRotatedRectangle
        CWIMAQViewer1.Image.Overlays(1).DrawText rotatedRect.Center, textOptions, Text
    Next
End Sub

Basic Particle Example

See Also

Threshold