Draw figures on an image after scroll
Overview
This code example shows a method to transform acquired coordinate to "after scroll" image and draw it.
You can draw X/Y axis or ruler on the screen by applying this method.
Specification of this example
Behavior
This example draws a line which is across the result of [Search] and parallel to x-axis to screen which display result of [Position Compensation].
This example indicates a simple usege of coordinate and scale conversion.
By using the method shown in this example, system can display X/Y axis or ruler which is adjusted for displaying image.
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 System automatically draws a line which is across the result of [Search] and parallel to x-axis to screen which display result of [Position Compensation].
How to implement
Scene data
Unit No.
|
Processing Item
|
0.
|
Camera Image Input
|
1.
|
Search
|
2.
|
Position Compensation
|
3.
|
Macro
|
The Macro Program below segment is to be set in '3.Macro'.
Macro Program
*MCRINIT
'Initialize '(1)
LENGTH# = 100
IMAGENO& = 0
UNITNO& = 1
Return
*MEASUREDISPG
'get Search result
GetUnitData UNITNO&, 6, SRCHX# '(2)
GetUnitData UNITNO&, 7, SRCHY#
TransformXY UNITNO&, IMAGENO&,10, SRCHX#, SRCHY#, ORGX#, ORGY#
'get x-axis direction '(3)
TransformXY UNITNO&, IMAGENO&,10, (SRCHX# + 1), SRCHY#, XDSTX#, XDSTY#
PREXDSTX# = XDSTX# - ORGX#
PREXDSTY# = XDSTY# - ORGY#
'get scale(pixel/length) '(4)
TransformDist UNITNO&, IMAGENO&,10, 1, DST#
SCALE# = 1 / DST#
COEF# = LENGTH#*SCALE#
XDSTX# = (XDSTX# - ORGX#)*COEF#
XDSTY# = (XDSTY# - ORGY#)*COEF#
'set graphical condition '(5)
SetDrawStyle PS_SOLID, 3, JUDGE_OK
'draw a line parallel to x-axis
DrawLine SRCHX#, SRCHY#, SRCHX# + XDSTX#, SRCHY# + XDSTY#, IMAGENO&
Return
The macro program is in
this link.
Explanation
(1)Initialize parameters(ex.length of line) when initialize measurement.
(2)Get the position x and y from [Search].
(3)Get the x-axis direction from result of [Search].
(4)Get pixels per unit length.
(5)Draw lines a line which is across the result of [Search] and parallel to x-axis.