CalculateCoefficients Method

NI Vision for Visual Basic

CalculateCoefficients Method

Syntax

CWIMAQVision.CalculateCoefficients SourceImage, Parameter, FullParticleReport, CoefficientsArray

Return Type

Long

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

Purpose

Obsolete—Use ParticleMeasurement instead. Calculates a specified coefficient for each detected particle.

Parameters

SourceImage As CWIMAQImage

The image used by the Particle method. CalculateCoefficients needs this image to get the coefficients.

Parameter As CWIMAQParticleParameters

The parameter you want to extract.

FullParticleReport As CWIMAQFullParticleReport

A report object containing the report that the Particle method generated.

CoefficientsArray As Variant

On return, a 1D array filled with the computed particle coefficients.

Example

Private Sub Run_Click()
    Dim report As New CWIMAQFullParticleReport
    Dim Area
    Dim Orientation
    Dim X
    Dim Y
    Dim i
    
    ' Threshold the image inplace
    CWIMAQVision1.Threshold CWIMAQViewer1.Image, CWIMAQViewer1.Image, _
                            , , , 255

    ' Do particle analysis
    CWIMAQVision1.Particle CWIMAQViewer1.Image, report

    ' Calculate the area of each particle
    CWIMAQVision1.CalculateCoefficients CWIMAQViewer1.Image, _
                                        cwimaqParticleArea, _
                                        report, Area
    ' Calculate the orientation of each particle
    CWIMAQVision1.CalculateCoefficients CWIMAQViewer1.Image, _
                                        cwimaqParticleOrientation, _
                                        report, Orientation
    ' Calculate the center of mass for each particle
    CWIMAQVision1.CalculateCoefficients CWIMAQViewer1.Image, _
                                        cwimaqParticleCenterMassX, _
                                        report, X
    CWIMAQVision1.CalculateCoefficients CWIMAQViewer1.Image, _
                                        cwimaqParticleCenterMassY, _
                                        report, Y
    
    ' For each particle, display the Area, Orientation, and mark the center of mass
    For i = 0 To report.Count - 1
        Dim Text As String
        Dim oval As New CWIMAQOval
        Dim point As New CWIMAQPoint
        Dim textOptions As New CWIMAQTextOptions
        Text = "A: " & CStr(Area(i)) & "  O: " & Format(Orientation(i), "##0.00")
        oval.Initialize X(i) - 4, Y(i) - 4, 8, 8
        CWIMAQViewer1.Image.Overlays(1).DrawOval oval, cwimaqDrawModePaint
        point.Initialize X(i), Y(i)
        textOptions.HorizontalAlignment = cwimaqHorizontalTextAlignmentCenter
        textOptions.Style = cwimaqTextStyleNormal
        textOptions.FontName = "Arial"
        textOptions.Size = 16
        textOptions.ForeColor = vbWhite
        CWIMAQViewer1.Image.Overlays(1).DrawText point, textOptions, Text
    Next
End Sub

Blob Analysis Example
Particle Orientation Example
Circle Distance Example