Make an average of last five times of measurement result and display it in Image Window
Overview
Make an average of last five times of measurement result and display it in Image Window.
This techinique is used for canceling small variation caused by noise.
Specification of this example
Behavior
Make an average of last five times of measurement result from target processing unit (in this example [Search]) and display it.
Screenshot
How to try this example
1.Click the link below, then the folder containing zip file automatically opens.
File
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 the average value of last five times is shown in Image Window.
How to implement
Scene data
Unit No.
|
Processing Item
|
0.
|
Camera Image Input
|
1.
|
Search
|
2.
|
Macro
|
The Macro Program below segment is to be set in '2.Macro'.
Macro Program
*MCRINIT
MAX& = 5 '(1)
Dim WRKCR#(MAX&)
For LP& = 0 To MAX& - 1
WRKCR#(LP&) = -1
Next
PARAM& = 1
Return
*MEASUREPROC
MYUNIT& = UnitNo
WRKCR#(CNT&) = UnitData(MYUNIT& - 1, "CR") '(2)
CNT& = CNT& + 1
If CNT& = MAX& Then
CNT& = 0
EndIf
Return
*MEASUREDISPG
SUM# = 0 '(3)
BUF$ = ""
For LP& = 0 To MAX& - 1
If WRKCR#(LP&) <> -1 Then
SUM# = SUM# + WRKCR#(LP&)
BUF$ = BUF$ + Str$(WRKCR#(LP&)) + " , "
PARAM& = LP& + 1
EndIf
Next
AVE# = SUM# / PARAM&
DrawTextG BUF$ + " -> AVE. " + Str$(AVE#), 10, 10, 0
Return
The macro program is in
this link.
Explanation
(1)Initialize parameters when initialize measurement.
(2)Get measurement results of previous unit via external reference data.
(3)Make an average of last five times of measurement result.