Halcon开发
机器视觉之C#联合Halcon
在使用halcon的算子之前,我们要先学会如何在图片上面进行标注。因为我们不仅要导出处理的结果,还要导出图像处理的过程。像是我们写代码批注一样,我们也要对图像进行图像批注。示例如下
Halcon窗口控制我们只需要做到一下几点即可
Halcon常用算子汇总
*打开窗口并且拿到窗口的句柄
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
*----绘图
*--绘制绿圆
dev_set_color('green')
disp_circle (WindowHandle, 64, 64, 64)
*--绘制空心圆
dev_set_draw ('margin')
dev_set_color('blue')
disp_circle (WindowHandle, 64, 64*3, 64)
*--绘制粗边缘空心圆
dev_set_draw ('margin')
dev_set_line_width (10)
dev_set_color('red')
disp_circle (WindowHandle, 64, 64*5, 64)
*--绘制1型矩形形边框,左上坐标+右下坐标
dev_set_color('yellow')
dev_set_line_width (3)
disp_rectangle1 (WindowHandle, 64*2, 16, 64*2+48, 80)
*--绘制2型矩形,中心点坐标+两边边长
dev_set_color ('white')
disp_rectangle2 (WindowHandle, 64*2+16, 64*2+16,0, 48, 32)
*--绘制箭头
disp_arrow (WindowHandle, 10, 10, 118, 118, 1)
*--添加注释
mes:= 'Hello halcon'
disp_message (WindowHandle,mes , 'window', 12, 12, 'black', 'true')
*--添加多个注释
mes:= '1.Hello halcon'
mes[1] := '2.Hello world'
mes[2] :='3.10点47分'
disp_message (WindowHandle, mes, 'window', 12*4, 12, 'black', 'true')
*--1型矩形和注释搭配
disp_x:=64*4
disp_y := 16
dev_set_color ('orange')
disp_rectangle1 (WindowHandle, disp_x, disp_y, disp_x+48,disp_y+ 80)
disp_message (WindowHandle, '这个是矩形', 'window', disp_x, disp_y, 'black', 'true')
Halcon 图形窗口显示文本
*----打开窗口
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
*---显示文本
disp_message (WindowHandle, ['Hello','Gong!'], 'window', 20, 12, 'magenta', 'true')
disp_message (WindowHandle, ['How are you!'], 'window', 30, 120, 'yellow', ['green','false'])
*----批量显示文本
*--声明数组
Angle := [0,90,180,270]
*--数组声明数组
*sin/cos三角函数
*rad角度制转弧度制
Row := 200 - sin(rad(Angle))*100
Column := 250 + cos(rad(Angle))*100
Color := ['green','red','blue','red']
*批量显示文本
disp_message (WindowHandle, Angle+' deg', 'window', Row, Column, Color, 'false')
gen_cross_contour_xld (Cross, 200, 250, 200, 0)