Save the measurement result of labeling to a file in csv format


Overview

Save the measurement result of labeling to a file in csv format.

Specification of this example


Behavior
This Sample saves the measurement result of labeling to a file in csv format.

Output Image


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 saves gravity point and area of each label to a file in csv format.
The path of the file is "C:\result.csv"

How to implement

Scene data
Unit No.
Processing Item
0.
Camera Image Input
1.
Labeling
2.
Label Data
3.
Macro
The Macro Program below segment is to be set in '3.Macro'.
Macro Program
*MCRINIT
    'Initialize                                                      '(1)
    WORKFOLDER$ = "C:\"
    WORKFILE$ = "result.csv"
    LABELINGUNITNO& = 1
    LABELDATAUNITNO& = 2

Return

*MEASUREPROC

    GetUnitData LABELINGUNITNO&, 5, LABELNUM&         '(2)

    If LABELNUM& > 0 Then
        Dim GRAVITYX#(LABELNUM&)
        Dim GRAVITYY#(LABELNUM&)
        Dim AREA#(LABELNUM&)

        For CNT& = 0 To (LABELNUM& - 1) Step 1
        SetUnitData LABELDATAUNITNO&, 121, CNT&         '(3)
        MeasureProc LABELDATAUNITNO&

        GetUnitData LABELDATAUNITNO&, 7, GRAVITYX#(CNT&)
        GetUnitData LABELDATAUNITNO&, 8, GRAVITYY#(CNT&)
        GetUnitData LABELDATAUNITNO&, 6, AREA#(CNT&)
        Next

        Open WORKFOLDER$ + WORKFILE$ FOR OUTPUT As #10         '(4)
        Print #10, "Label No., Gravity X, Gravity Y, Area"
        For CNT& = 0 To (LABELNUM& - 1) Step 1
        Print #10, Str$(CNT&) + ", " + Str$(GRAVITYX#(CNT&)) + ", " + Str$(GRAVITYY#(CNT&)) + ", " + Str$(AREA#(CNT&)) 
        Next 

        Close #10
    EndIf

Return

The macro program is in refthis link.
Explanation
(1)Initialize parameters(ex.path of the file) when initialize measurement.
(2)Get the number of labels of Labeling.
(3)Get gravity X, gravity Y, and area of each label.
(4)Save the data to a file in csv format.