dev_update_window('off')
dev_open_window(0, 0, 512, 512, 'black', WindowHandle) //打开窗口
stop() //程序中断
*dev_close_window() //关闭窗口
read_image (Bond, 'die/die_03') //读取图片
dev_display(Bond) //显示图片
set_display_font(WindowHandle, 16, 'mono', 'true', 'false')
disp_continue_message(WindowHandle, 'black', 'true')
stop()
threshold(Bond, Region, 128, 255)//二值化
shape_trans(Region, Die, 'rectangle2')//形状转换
dev_set_color('green') //建立矩形框 框选检测部分 建立颜色线宽
dev_set_line_width(3)
dev_set_draw('margin') //绘制矩形框
dev_display(Die)
disp_continue_message(WindowHandle, 'black', 'true')
stop()
reduce_domain(Bond, Die, DieGrey)
threshold(DieGrey, Wires, 0, 50)
fill_up_shape(Wires, WiresFillUp, 'area', 1, 100)
dev_display(Bond)
dev_set_draw('fill')
dev_set_color('red')
dev_display(WiresFillUp)
disp_continue_message(WindowHandle, 'black', 'true')
stop()
opening_circle(WiresFillUp, Balls, 15.5)
dev_set_color('green')
dev_display(Balls)
stop()
connection(Balls, SingleBalls)
select_shape(SingleBalls, Intermediateball, 'circularity', 'and', 0.85, 1.0)
sort_region(Intermediateball, FinalBalls, 'first_point', 'true', 'column')
dev_display(Bond)
dev_set_colored(12)
dev_display(FinalBalls)
disp_continue_message(WindowHandle, 'black', 'true')
stop()
smallest_circle(FinalBalls, Row, Column, Radius) //在FinalBalls的位置上生成一个最小周围圆
NumBalls := |Radius| //将Radius的结果传递给NumBalls(圆的个数)
Diameter := 2*Radius
MeanDiameter := min(Diameter)
dev_display(Bond)
disp_circle(WindowHandle, Row, Column, Radius)
dev_set_color('white')
disp_message(WindowHandle,'D: ' +Diameter$'.4','image',Row - 2 * Radius,Column, 'white', 'false')
dev_update_window('on')
HalconLen2-示例程序分析
于 2024-04-17 13:40:36 首次发布