9
在draw.bas文件中添加主界面【学习模板】按钮响应的函数并关联动作函数。
↓
'主界面按下学习模板按钮时响应的函数
GLOBAL SUB btn_sel_loc()
ZV_LATCHSETSIZE(0, HMI_CONTROLSIZEX(11, 60), HMI_CONTROLSIZEY(11, 60)) '设置创建模板窗口锁存通道0的锁存大小
SET_COLOR(RGB(0,255,0)) '指定draw指令使用的颜色
ZV_LATCHCLEAR(0) '将锁存通道0清空
ZV_LATCH(grabImg, 0) '显示采集图像显示到锁存通道0中
ZV_LATCH(colorSubImg, 1) '显示模板图像显示到锁存通道1中
'图像roi坐标转控件roi
is_redraw = 0
d_is_rtn_loc = 0
TABLE(111, d_locator_roi(0), d_locator_roi(1),d_locator_roi(2),d_locator_roi(3))
ZV_POSFROMIMG(0, 2, 111, 111) '图像坐标转换到HMI控件坐标
HMI_SHOWWINDOW(11)
END SUB
↓
10
在draw.bas文件中添加模板区域更新绘制函数。
'根据鼠标操作更新定位器的区域即学习模板的有效区域
GLOBAL SUB update_locator()
if mouse_scan(21) = 1 then '扫描鼠标按下操作
is_set_roi_m_down = 1
sr_mpos_x = table(21)
sr_mpos_y = table(22)
hit_pos = ZV_HMIADJRECT(sr_mpos_x, sr_mpos_y, 111, -1) '只有按下时可以改变击中位置
is_redraw = 1
endif
if mouse_scan(21) = -1 then '扫描鼠标松开操作
is_set_roi_m_down = 0
sr_mpos_x = table(21)
sr_mpos_y = table(22)
ZV_HMIADJRECT(sr_mpos_x, sr_mpos_y, 111, hit_pos)
is_redraw = 1
endif
if (is_set_roi_m_down and MOUSE_state(21)) then
sr_mpos_x = table(21)
sr_mpos_y = table(22)
ZV_HMIADJRECT(sr_mpos_x, sr_mpos_y, 111, hit_pos)
is_redraw = 1
endif
if (1 = is_redraw) then
'控件roi坐标转图像roi坐标
is_redraw = 0
ZV_POSTOIMG(0, 2, 111, 50) 'TABLE(50)作为中间变量临时使用
d_locator_roi(0) = TABLE(50)
d_locator_roi(1) = TABLE(51)
d_locator_roi(2) = TABLE(52)
d_locator_roi(3) = TABLE(53)
SET_REDRAW
endif
END SUB
'根据更新的鼠标位置坐标绘制定位器roi
GLOBAL SUB draw_locator()
DRAWRECT(TABLE(111), TABLE(112), TABLE(113), TABLE(114))
local cx,cy
cx = (TABLE(111) + TABLE(113)) / 2
cy = (TABLE(112) + TABLE(114)) / 2
DRAWLINE(cx-5, cy, cx+5, cy) '中心十字线
DRAWLINE(cx, cy-5, cx, cy+5)
END SUB
11
在main.bas文件中添加【截取模板】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下截取模板按钮后响应的函数
global sub btn_getSubImg()
LOCAL mod_w,mod_h
ZV_IMGGETSUB(grabImg, subImg, d_locator_roi(0), d_locator_roi(1), d_locator_roi(2)-d_locator_roi(0)+1, d_locator_roi(3)-d_locator_roi(1)+1)
ZV_IMGINFO(subImg,0)
mod_w = TABLE(0)
mod_h = TABLE(1)
ZV_REGENRECT(modRe,0,0,mod_w, mod_h)
ZV_LATCHCLEAR(1)
ZV_LATCH(subImg, 1)
end sub
↓
12
点击[元件]→[新建窗口],新建编辑模板窗口,设计窗口布局。
注意:需要设置窗口垄断属性。
13
在draw.bas文件中添加创建模板界面【橡皮擦】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下橡皮擦按钮时响应的函数
GLOBAL SUB btn_sel_erase()
ZV_LATCHSETSIZE(1, HMI_CONTROLSIZEX(12, 1), HMI_CONTROLSIZEY(12, 1)) '设置锁存的大小
SET_COLOR(RGB(0,255,0)) '设置绘制时画笔使用的颜色
ZV_LATCHCLEAR(1) '清空锁存
ZV_IMGCOPY(subImg, copy_subImg) '复制模板子图像到copy_subImg图像变量中
ZV_REGION(copy_subImg, modRe, 1, 0) '在模板图像上绘制modRe图像的非有效区域,绘制颜色为黑色,用于掩模
ZV_LATCH(copy_subImg, 1) '显示复制的模板图
HMI_SHOWWINDOW(12) '打开编辑模板窗口
end sub
↓
14
在draw.bas文件中添加橡皮擦更新绘制函数。
'根据鼠标操作更新橡皮擦擦除/恢复区域的位置
GLOBAL SUB update_eraser()
DIM c_size_eraser '橡皮擦在控件上对应的尺寸
DIM eraser_pos_x,eraser_pos_y
d_mouse_s = MOUSE_STATE(21) '鼠标处于按下状态时
eraser_pos_x = TABLE(21)
eraser_pos_y = TABLE(22)
c_size_eraser = ZV_LENFROMIMG(0, d_eraser_size) '将橡皮擦的图像尺寸转换成控件尺寸
c_rect(0, eraser_pos_x - c_size_eraser, eraser_pos_y - c_size_eraser, eraser_pos_x + c_size_eraser, eraser_pos_y + c_size_eraser)
'绘制以(eraser_pos_x,eraser_pos_y)为中心,2*c_size_eraser为边长的正方形橡皮擦区域
DIM hmi_w,hmi_h
if (eraser_pos_x >= c_size_eraser) and (eraser_pos_y >= c_size_eraser) and (eraser_pos_x <= HMI_CONTROLSIZEX(12, 1) - c_size_eraser)and (eraser_pos_y <= HMI_CONTROLSIZEy(12, 1) - c_size_eraser) THEN
SET_REDRAW(0,0, HMI_CONTROLSIZEX(12, 1), HMI_CONTROLSIZEY(12, 1))'重新绘制编辑模板窗口上的锁存通道0区域
endif
if d_mouse_s = 1 and d_edit_m = 1 then '如果鼠标处于按下状态且编辑模板标志=1时
btn_pro_eraser() '执行处理橡皮擦函数
endif
END SUB
'处理橡皮擦函数
global sub btn_pro_eraser()
ZVOBJECT tmp_re
TABLE(121, c_rect(0), c_rect(1))
ZV_POSTOIMG(1, 1, 121, 121)
ZV_REGENRECT(tmp_re, TABLE(121), TABLE(122), 2 * d_eraser_size + 1, 2 * d_eraser_size + 1)
if (d_isMask_m = 1) then '屏蔽
ZV_REDIFF(modRe, tmp_re, modRe) '计算modRe和tmp_re的差集并存放到modRe中
else '恢复
ZV_REUNION(modRe, tmp_re, modRe) '计算modRe和tmp_re的并集并存放到modRe中
endif
ZV_IMGCOPY(subImg, copy_subImg) '复制模板子图像到copy_subImg图像变量中
ZV_REGION(copy_subImg, modRe, 1, 0) '在模板图像上绘制modRe图像的非有效区域,绘制颜色为黑色,用于掩模
ZV_LATCH(copy_subImg, 1) '显示复制的模板图
end sub
'更新绘制橡皮擦区域
GLOBAL SUB draw_eraser()
if d_edit_m = 0 then '如果编辑模板标志
return '返回子函数,不继续往下执行
endif
DRAWRECT(c_rect(0), c_rect(1), c_rect(2), c_rect(3))'绘制橡皮擦区域
END SUB
15
在main.bas文件中添加编辑模板界面【创建模板】按钮响应的函数并关联动作函数。
↓
'编辑模板界面按下创建模板按钮时响应的函数
GLOBAL SUB btn_loc_creModel()
d_is_creModel = 1
ZV_SHAPECREATERE(subImg, modRe,s_mod, d_mod_param(0), d_mod_param(1), d_mod_param(2), d_mod_param(3), d_mod_param(4), d_mod_param(5), d_mod_param(6), d_mod_param(7), d_mod_param(8))
'创建模板
ZV_SHAPECONTOURS(s_mod, contlist1, 0) '获取第0层金字塔上的模板轮廓
ZV_GRAYTORGB(subImg, colorSubImg) '灰度图转换成RGB图
ZV_IMGINFO(colorSubImg, 0) '获取colorSubImg图像信息,并存放到table0中
ZV_GETRIGIDVECTOR(mat_rigid1, 0, 0, 0, TABLE(0)/2, TABLE(1)/2, 0)'计算刚性变换矩阵
ZV_CONTAFFINE(contlist1, mat_rigid1, tsContlist1)'对轮廓或轮廓序列进行仿射变换
ZV_CONTLIST(colorSubImg, tsContlist1, ZV_COLOR(0, 255, 0), 0)'在colorSubImg图像上绘制绿色的轮廓序列
ZV_LATCHCLEAR(2)
ZV_LATCH(colorSubImg, 2)
end sub
↓
16
在draw.bas文件中添加编辑模板界面【确定】按钮响应的函数并关联动作函数。
↓
'编辑模板界面按下确定按钮时执行的函数
GLOBAL SUB btn_erase_cfm()
ZV_LATCHCLEAR(0)
ZV_LATCH(grabImg, 0) '显示图像在锁存上
HMI_CLOSEWINDOW(12) '关闭编辑模板窗口
END SUB
↓
17
在main.bas文件中添加创建模板界面【测试】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下测试按钮时响应的函数
GLOBAL SUB btn_loc_test()
if (d_is_creModel = 0) then
?"未创建模板!"
return
endif
'开始匹配
TICKS = 0
ZVOBJECT match_rst, sImg, colorImg
ZV_GAUSSBLUR(grabImg, sImg, 3)
ZV_SHAPEFIND(s_mod, sImg, match_rst, d_match_param(0), d_match_param(1), d_match_param(2), d_match_param(3), d_match_param(4), d_match_param(5), d_match_param(6))
ZV_MATINFO(match_rst, 0)
ZV_GRAYTORGB(sImg, colorImg)
if TABLE(0) > 0 then
local rowr
for rowr = 0 to TABLE(0)-1
ZV_MATGETROW(match_rst, rowr, 5, 3) '获取match_rst矩阵中第rowr行的数据到table中,table最大长度5
if(rowr = 0) then
d_match_rst(0) = TABLE(3)
d_match_rst(1) = TABLE(4)
d_match_rst(2) = TABLE(5)
d_match_rst(3) = TABLE(6)
d_match_rst(4) = TABLE(7)
ZV_GETRIGIDVECTOR(mat_rigid1, 0, 0, 0, TABLE(4), TABLE(5), TABLE(6))'计算刚性变换矩阵
ZV_CONTAFFINE(contlist1, mat_rigid1, tsContlist1)'对轮廓或轮廓序列进行仿射变换
ZV_CONTLIST(colorImg, tsContlist1, ZV_COLOR(0, 255, 0), 0)'在colorSubImg图像上绘制绿色的轮廓序列
endif
next
else
d_match_rst(0) = -1
d_match_rst(1) = -1
d_match_rst(2) = -1
d_match_rst(3) = -1
d_match_rst(4) = -1
endif
d_match_time = abs(TICKS) '匹配时间
ZV_LATCH(colorImg, 0)
end sub
↓
18
在draw.bas文件中添加创建模板界面【确定】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下确定按钮时响应的函数
GLOBAL SUB btn_loc_cfm()
grab_switch = 0 '关闭补正源的连续采集
d_is_rtn_loc = 1
ZV_LATCHCLEAR(0)
ZV_LATCH(grabImg, 0) '显示图像在锁存上
ZV_LATCH(grabImg, 1) '显示图像在锁存上
HMI_CLOSEWINDOW(11)
END SUB
↓
19
在main.bas文件中添加主界面【单次执行】按钮响应的函数并关联动作函数。
↓
'主界面按下单次执行按钮时响应的函数
GLOBAL SUB btn_test()
btn_grab() '单次采集图像
btn_loc_test() '匹配测试函数
END SUB
↓
20
在main.bas文件中添加主界面【连续运行】按钮响应的函数并关联动作函数。
↓
'主界面点击连续运行按钮时响应的函数
GLOBAL SUB btn_run()
if(run_switch = 1) then
?"已开启连续运行,请勿重复操作!"
return
endif
run_switch = 1
if (1 = run_switch) then
if (0 = PROC_STATUS(main_task_id)) then
RUNTASK main_task_id, main_task
endif
endif
END SUB
'连续运行主任务内容
main_task:
while(1)
if (0 = run_switch) then
exit while
endif
'以下执行相关定位操作
btn_grab()
btn_loc_test()
wend
END
↓
21
在main.bas文件中添加主界面【停止运行】按钮响应的函数并关联动作函数。
↓
'主界面点击停止执行按钮时响应的函数
GLOBAL SUB btn_stop()
if(run_switch = 0) then
?"未开启连续运行!"
return
endif
run_switch = 0
END SUB
↓
仿真演示效果
在draw.bas文件中添加主界面【学习模板】按钮响应的函数并关联动作函数。
↓
'主界面按下学习模板按钮时响应的函数
GLOBAL SUB btn_sel_loc()
ZV_LATCHSETSIZE(0, HMI_CONTROLSIZEX(11, 60), HMI_CONTROLSIZEY(11, 60)) '设置创建模板窗口锁存通道0的锁存大小
SET_COLOR(RGB(0,255,0)) '指定draw指令使用的颜色
ZV_LATCHCLEAR(0) '将锁存通道0清空
ZV_LATCH(grabImg, 0) '显示采集图像显示到锁存通道0中
ZV_LATCH(colorSubImg, 1) '显示模板图像显示到锁存通道1中
'图像roi坐标转控件roi
is_redraw = 0
d_is_rtn_loc = 0
TABLE(111, d_locator_roi(0), d_locator_roi(1),d_locator_roi(2),d_locator_roi(3))
ZV_POSFROMIMG(0, 2, 111, 111) '图像坐标转换到HMI控件坐标
HMI_SHOWWINDOW(11)
END SUB
↓
10
在draw.bas文件中添加模板区域更新绘制函数。
'根据鼠标操作更新定位器的区域即学习模板的有效区域
GLOBAL SUB update_locator()
if mouse_scan(21) = 1 then '扫描鼠标按下操作
is_set_roi_m_down = 1
sr_mpos_x = table(21)
sr_mpos_y = table(22)
hit_pos = ZV_HMIADJRECT(sr_mpos_x, sr_mpos_y, 111, -1) '只有按下时可以改变击中位置
is_redraw = 1
endif
if mouse_scan(21) = -1 then '扫描鼠标松开操作
is_set_roi_m_down = 0
sr_mpos_x = table(21)
sr_mpos_y = table(22)
ZV_HMIADJRECT(sr_mpos_x, sr_mpos_y, 111, hit_pos)
is_redraw = 1
endif
if (is_set_roi_m_down and MOUSE_state(21)) then
sr_mpos_x = table(21)
sr_mpos_y = table(22)
ZV_HMIADJRECT(sr_mpos_x, sr_mpos_y, 111, hit_pos)
is_redraw = 1
endif
if (1 = is_redraw) then
'控件roi坐标转图像roi坐标
is_redraw = 0
ZV_POSTOIMG(0, 2, 111, 50) 'TABLE(50)作为中间变量临时使用
d_locator_roi(0) = TABLE(50)
d_locator_roi(1) = TABLE(51)
d_locator_roi(2) = TABLE(52)
d_locator_roi(3) = TABLE(53)
SET_REDRAW
endif
END SUB
'根据更新的鼠标位置坐标绘制定位器roi
GLOBAL SUB draw_locator()
DRAWRECT(TABLE(111), TABLE(112), TABLE(113), TABLE(114))
local cx,cy
cx = (TABLE(111) + TABLE(113)) / 2
cy = (TABLE(112) + TABLE(114)) / 2
DRAWLINE(cx-5, cy, cx+5, cy) '中心十字线
DRAWLINE(cx, cy-5, cx, cy+5)
END SUB
11
在main.bas文件中添加【截取模板】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下截取模板按钮后响应的函数
global sub btn_getSubImg()
LOCAL mod_w,mod_h
ZV_IMGGETSUB(grabImg, subImg, d_locator_roi(0), d_locator_roi(1), d_locator_roi(2)-d_locator_roi(0)+1, d_locator_roi(3)-d_locator_roi(1)+1)
ZV_IMGINFO(subImg,0)
mod_w = TABLE(0)
mod_h = TABLE(1)
ZV_REGENRECT(modRe,0,0,mod_w, mod_h)
ZV_LATCHCLEAR(1)
ZV_LATCH(subImg, 1)
end sub
↓
12
点击[元件]→[新建窗口],新建编辑模板窗口,设计窗口布局。
注意:需要设置窗口垄断属性。
13
在draw.bas文件中添加创建模板界面【橡皮擦】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下橡皮擦按钮时响应的函数
GLOBAL SUB btn_sel_erase()
ZV_LATCHSETSIZE(1, HMI_CONTROLSIZEX(12, 1), HMI_CONTROLSIZEY(12, 1)) '设置锁存的大小
SET_COLOR(RGB(0,255,0)) '设置绘制时画笔使用的颜色
ZV_LATCHCLEAR(1) '清空锁存
ZV_IMGCOPY(subImg, copy_subImg) '复制模板子图像到copy_subImg图像变量中
ZV_REGION(copy_subImg, modRe, 1, 0) '在模板图像上绘制modRe图像的非有效区域,绘制颜色为黑色,用于掩模
ZV_LATCH(copy_subImg, 1) '显示复制的模板图
HMI_SHOWWINDOW(12) '打开编辑模板窗口
end sub
↓
14
在draw.bas文件中添加橡皮擦更新绘制函数。
'根据鼠标操作更新橡皮擦擦除/恢复区域的位置
GLOBAL SUB update_eraser()
DIM c_size_eraser '橡皮擦在控件上对应的尺寸
DIM eraser_pos_x,eraser_pos_y
d_mouse_s = MOUSE_STATE(21) '鼠标处于按下状态时
eraser_pos_x = TABLE(21)
eraser_pos_y = TABLE(22)
c_size_eraser = ZV_LENFROMIMG(0, d_eraser_size) '将橡皮擦的图像尺寸转换成控件尺寸
c_rect(0, eraser_pos_x - c_size_eraser, eraser_pos_y - c_size_eraser, eraser_pos_x + c_size_eraser, eraser_pos_y + c_size_eraser)
'绘制以(eraser_pos_x,eraser_pos_y)为中心,2*c_size_eraser为边长的正方形橡皮擦区域
DIM hmi_w,hmi_h
if (eraser_pos_x >= c_size_eraser) and (eraser_pos_y >= c_size_eraser) and (eraser_pos_x <= HMI_CONTROLSIZEX(12, 1) - c_size_eraser)and (eraser_pos_y <= HMI_CONTROLSIZEy(12, 1) - c_size_eraser) THEN
SET_REDRAW(0,0, HMI_CONTROLSIZEX(12, 1), HMI_CONTROLSIZEY(12, 1))'重新绘制编辑模板窗口上的锁存通道0区域
endif
if d_mouse_s = 1 and d_edit_m = 1 then '如果鼠标处于按下状态且编辑模板标志=1时
btn_pro_eraser() '执行处理橡皮擦函数
endif
END SUB
'处理橡皮擦函数
global sub btn_pro_eraser()
ZVOBJECT tmp_re
TABLE(121, c_rect(0), c_rect(1))
ZV_POSTOIMG(1, 1, 121, 121)
ZV_REGENRECT(tmp_re, TABLE(121), TABLE(122), 2 * d_eraser_size + 1, 2 * d_eraser_size + 1)
if (d_isMask_m = 1) then '屏蔽
ZV_REDIFF(modRe, tmp_re, modRe) '计算modRe和tmp_re的差集并存放到modRe中
else '恢复
ZV_REUNION(modRe, tmp_re, modRe) '计算modRe和tmp_re的并集并存放到modRe中
endif
ZV_IMGCOPY(subImg, copy_subImg) '复制模板子图像到copy_subImg图像变量中
ZV_REGION(copy_subImg, modRe, 1, 0) '在模板图像上绘制modRe图像的非有效区域,绘制颜色为黑色,用于掩模
ZV_LATCH(copy_subImg, 1) '显示复制的模板图
end sub
'更新绘制橡皮擦区域
GLOBAL SUB draw_eraser()
if d_edit_m = 0 then '如果编辑模板标志
return '返回子函数,不继续往下执行
endif
DRAWRECT(c_rect(0), c_rect(1), c_rect(2), c_rect(3))'绘制橡皮擦区域
END SUB
15
在main.bas文件中添加编辑模板界面【创建模板】按钮响应的函数并关联动作函数。
↓
'编辑模板界面按下创建模板按钮时响应的函数
GLOBAL SUB btn_loc_creModel()
d_is_creModel = 1
ZV_SHAPECREATERE(subImg, modRe,s_mod, d_mod_param(0), d_mod_param(1), d_mod_param(2), d_mod_param(3), d_mod_param(4), d_mod_param(5), d_mod_param(6), d_mod_param(7), d_mod_param(8))
'创建模板
ZV_SHAPECONTOURS(s_mod, contlist1, 0) '获取第0层金字塔上的模板轮廓
ZV_GRAYTORGB(subImg, colorSubImg) '灰度图转换成RGB图
ZV_IMGINFO(colorSubImg, 0) '获取colorSubImg图像信息,并存放到table0中
ZV_GETRIGIDVECTOR(mat_rigid1, 0, 0, 0, TABLE(0)/2, TABLE(1)/2, 0)'计算刚性变换矩阵
ZV_CONTAFFINE(contlist1, mat_rigid1, tsContlist1)'对轮廓或轮廓序列进行仿射变换
ZV_CONTLIST(colorSubImg, tsContlist1, ZV_COLOR(0, 255, 0), 0)'在colorSubImg图像上绘制绿色的轮廓序列
ZV_LATCHCLEAR(2)
ZV_LATCH(colorSubImg, 2)
end sub
↓
16
在draw.bas文件中添加编辑模板界面【确定】按钮响应的函数并关联动作函数。
↓
'编辑模板界面按下确定按钮时执行的函数
GLOBAL SUB btn_erase_cfm()
ZV_LATCHCLEAR(0)
ZV_LATCH(grabImg, 0) '显示图像在锁存上
HMI_CLOSEWINDOW(12) '关闭编辑模板窗口
END SUB
↓
17
在main.bas文件中添加创建模板界面【测试】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下测试按钮时响应的函数
GLOBAL SUB btn_loc_test()
if (d_is_creModel = 0) then
?"未创建模板!"
return
endif
'开始匹配
TICKS = 0
ZVOBJECT match_rst, sImg, colorImg
ZV_GAUSSBLUR(grabImg, sImg, 3)
ZV_SHAPEFIND(s_mod, sImg, match_rst, d_match_param(0), d_match_param(1), d_match_param(2), d_match_param(3), d_match_param(4), d_match_param(5), d_match_param(6))
ZV_MATINFO(match_rst, 0)
ZV_GRAYTORGB(sImg, colorImg)
if TABLE(0) > 0 then
local rowr
for rowr = 0 to TABLE(0)-1
ZV_MATGETROW(match_rst, rowr, 5, 3) '获取match_rst矩阵中第rowr行的数据到table中,table最大长度5
if(rowr = 0) then
d_match_rst(0) = TABLE(3)
d_match_rst(1) = TABLE(4)
d_match_rst(2) = TABLE(5)
d_match_rst(3) = TABLE(6)
d_match_rst(4) = TABLE(7)
ZV_GETRIGIDVECTOR(mat_rigid1, 0, 0, 0, TABLE(4), TABLE(5), TABLE(6))'计算刚性变换矩阵
ZV_CONTAFFINE(contlist1, mat_rigid1, tsContlist1)'对轮廓或轮廓序列进行仿射变换
ZV_CONTLIST(colorImg, tsContlist1, ZV_COLOR(0, 255, 0), 0)'在colorSubImg图像上绘制绿色的轮廓序列
endif
next
else
d_match_rst(0) = -1
d_match_rst(1) = -1
d_match_rst(2) = -1
d_match_rst(3) = -1
d_match_rst(4) = -1
endif
d_match_time = abs(TICKS) '匹配时间
ZV_LATCH(colorImg, 0)
end sub
↓
18
在draw.bas文件中添加创建模板界面【确定】按钮响应的函数并关联动作函数。
↓
'创建模板界面按下确定按钮时响应的函数
GLOBAL SUB btn_loc_cfm()
grab_switch = 0 '关闭补正源的连续采集
d_is_rtn_loc = 1
ZV_LATCHCLEAR(0)
ZV_LATCH(grabImg, 0) '显示图像在锁存上
ZV_LATCH(grabImg, 1) '显示图像在锁存上
HMI_CLOSEWINDOW(11)
END SUB
↓
19
在main.bas文件中添加主界面【单次执行】按钮响应的函数并关联动作函数。
↓
'主界面按下单次执行按钮时响应的函数
GLOBAL SUB btn_test()
btn_grab() '单次采集图像
btn_loc_test() '匹配测试函数
END SUB
↓
20
在main.bas文件中添加主界面【连续运行】按钮响应的函数并关联动作函数。
↓
'主界面点击连续运行按钮时响应的函数
GLOBAL SUB btn_run()
if(run_switch = 1) then
?"已开启连续运行,请勿重复操作!"
return
endif
run_switch = 1
if (1 = run_switch) then
if (0 = PROC_STATUS(main_task_id)) then
RUNTASK main_task_id, main_task
endif
endif
END SUB
'连续运行主任务内容
main_task:
while(1)
if (0 = run_switch) then
exit while
endif
'以下执行相关定位操作
btn_grab()
btn_loc_test()
wend
END
↓
21
在main.bas文件中添加主界面【停止运行】按钮响应的函数并关联动作函数。
↓
'主界面点击停止执行按钮时响应的函数
GLOBAL SUB btn_stop()
if(run_switch = 0) then
?"未开启连续运行!"
return
endif
run_switch = 0
END SUB
↓
仿真演示效果