Set the parameter and region setting of the processing unit from the measurement result of other processing unit

Overview

This sample sets the parameter and region setting of the processing unit from the measurement result of other processing unit.

Specification of this example


Behavior
This sample extracts labels except back ground, and calculates the average valus of RGB in the regions which is set on the center of gravity of each label.

Screenshot


How to try this example
1.Click the link below, then the folder containing zip file automatically opens.
refFile

2.Right-click and hold on the zip file, and drop it on working window of FJ system. The images and scene data in zip file are loaded on the program automatically.

3.Re-measure the image. Then System automatically extracts labels except back ground, and calculates the average valus of RGB in the regions which is set on the center of gravity of each label.
The positions of center of gravity and the average values of RGB of each label are displayed in Image Window.

How to implement

Scene data
Unit No.
Processing Item
0.
Camera Image Input
1.
Labeling
2.
Macro
3.
End
4.
Label Data
5.
Color Data
The Macro Program below segment is to be set in '2.Macro'.
Macro Program
*MCRINIT
    LABELUNITNO& = 1        '(1)
    LABELDATAUNITNO& = 4
    COLORDATAUNITNO& = 5
    CPYFIGNO& = 0
    LEN& = 25
    FONTSIZE& = 24

    Dim FIGDATA&(30)
    Dim POSX#(10), POSY#(10), R&(10), G&(10), B&(10)

Return

*MEASUREPROC

     GetUnitData LABELUNITNO&, 5, LABELCOUNT&        '(2)

    If LABELCOUNT& > 0 Then
        '(3)
        For COUNT& = 0 To (LABELCOUNT& - 1) Step 1
        SetUnitData LABELDATAUNITNO&, "labelNo", COUNT&
        MeasureProc LABELDATAUNITNO&

        GetUnitData LABELDATAUNITNO&, "X", POSX#(COUNT&)
        GetUnitData LABELDATAUNITNO&, "Y", POSY#(COUNT&)

        '(4) 
        GetUnitFigure COLORDATAUNITNO&, CPYFIGNO&, FIGDATA&() 

        '(5)
        FIGDATA&(2) = Int(POSX#(COUNT&)) - LEN&
        FIGDATA&(4) = Int(POSX#(COUNT&)) + LEN&
        FIGDATA&(3) = Int(POSY#(COUNT&)) - LEN&
        FIGDATA&(5) = Int(POSY#(COUNT&)) + LEN&
        SetUnitFigure COLORDATAUNITNO&, CPYFIGNO&, FIGDATA&()

        '(6)
        MeasureProc COLORDATAUNITNO&         
        GetUnitData COLORDATAUNITNO&, "AR", R&(COUNT&)
        GetUnitData COLORDATAUNITNO&, "AG", G&(COUNT&)
        GetUnitData COLORDATAUNITNO&, "AB", B&(COUNT&)

        Next
    EndIf

Return

*MEASUREDISPG
    SetTextStyle FONTSIZE&, TA_TOP, JUDGE_OK, 0, FONTSTYLE_BOLD + FONTSTYLE_UNDERLINE

    '(7)
    For COUNT&= 0 To (LABELCOUNT& - 1) Step 1
        MESSAGE$ = "No." + Str$(COUNT& + 1) + "  X : " + Str2$(POSX#(COUNT&), 3, 2, 1, 0) + ", Y : " + Str2$(POSY#(COUNT&), 3, 2, 1, 0)
        MESSAGE$ = MESSAGE$ + ", R: " + Str2$(R&(COUNT&), 3, 0, 1, 0) + ", G: " + Str2$(G&(COUNT&), 3, 0, 1, 0) + ", B: " + Str2$(B&(COUNT&), 3, 0, 1, 0)
        DrawTextG MESSAGE$, 10, (20 * COUNT&), 0
    Next

Return

The macro program is in refthis link.
Explanation
(1)Initialize parameters(ex.Unit No of processing units) when initialize measurement.
(2)Get the label count.
(3)Get the center of gravity of each label.
(4)Get the region of [Color Data].
(5)Set the region whose corner position is specified distance away from the center of gravity of each label (50 pixels, height and width).
(6)Execute [Color Data] and get the values of RGB.
(7)Display the positions of center of gravity and the average values of RGB of each label in Image Window.