一个ball例程带你进入 Halcon 世界

* 此例程来自halcon自带例程,请打开 halcon-》ctrl+E 打开例程-》搜索框中输入ball added by xiejl
* ball.hdev: Inspection of Ball Bonding * dev_update_window ('off') dev_close_window () dev_open_window (0, 0, 728, 512, 'black', WindowID) read_image (Bond, 'die/die_03') dev_display (Bond) set_display_font (WindowID, 14, 'mono', 'true', 'false') disp_continue_message (WindowID, 'black', 'true') stop () threshold (Bond, Bright, 100, 255) shape_trans (Bright, Die, 'rectangle2') dev_set_color ('green') dev_set_line_width (3) dev_set_draw ('margin') dev_display (Die) disp_continue_message (WindowID, 'black', 'true') stop () reduce_domain (Bond, Die, DieGrey) threshold (DieGrey, Wires, 0, 50) fill_up_shape (Wires, WiresFilled, 'area', 1, 100) dev_display (Bond) dev_set_draw ('fill') dev_set_color ('red') dev_display (WiresFilled) disp_continue_message (WindowID, 'black', 'true') stop () opening_circle (WiresFilled, Balls, 15.5) dev_set_color ('green') dev_display (Balls) disp_continue_message (WindowID, 'black', 'true') stop () connection (Balls, SingleBalls) select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0) sort_region (IntermediateBalls, FinalBalls, 'first_point', 'true', 'column') dev_display (Bond) dev_set_colored (12) dev_display (FinalBalls) disp_continue_message (WindowID, 'black', 'true') stop () smallest_circle (FinalBalls, Row, Column, Radius) NumBalls := |Radius| Diameter := 2*Radius meanDiameter := sum(Diameter)/NumBalls mimDiameter := min(Diameter) dev_display (Bond) disp_circle (WindowID, Row, Column, Radius) dev_set_color ('white') for i := 1 to NumBalls by 1 if (fmod(i,2)=1) disp_message (WindowID, 'D: '+Diameter[i-1], 'image', Row[i-1]-2.7*Radius[i-1], max([Column[i-1]-60,0]), 'white', 'false') else disp_message (WindowID, 'D: '+Diameter[i-1], 'image', Row[i-1]+1.2*Radius[i-1], max([Column[i-1]-60,0]), 'white', 'false') endif endfor * dump_window (WindowID, 'tiff_rgb', './ball') dev_set_color ('green') dev_update_window ('on') disp_continue_message (WindowID, 'black', 'true') stop () dev_close_window ()

  可以看到 图像的处理就是红色之外的代码,没有几句。

  先来看看红色部分的代码:

  dev_update_window:帮助文档上是这么说的---此算子决定 所有由其他某一个算子返回的所有图形对象是否显示在活动的图形窗口之上(‘on'为默认参数,代表打开此更新,'off'表示关闭此更新,所有更新由我们手动打开)。参数的选择对于我们输出对象在某一单步执行时是没有影响的,执行之后,图形输出对象依然可以显示在活动的图形窗口之上。参数选择应该被置为'off',只有在我们选择的图形对象应该被显示在图形窗口之上时,我们应该手动调用算子:dev_display算子显示此对象(包括 image, xld, region等其他图形对象)。理解了吗?呵呵

  dev_close_window:这是halcon中比较简单的内部函数,就是将图形显示窗口关闭。当然我们可以通过HDevelop的菜单栏-》窗口-》打开图形窗口,打开多个图形窗口。

  dev_open_window:这没什么好说的,就是将上面关闭的图形窗口重新打开。

  dev_display:如果我们通过调用dev_update_window(’off')语句,关闭窗口的更新,我们必须手动调用dev_display()内部操作来显示对象(比如imag,region,xld等其他图形对象)。

  stop: 这是应该是halcon中最简单的语句了,相当于C中的system("pause"),让程序暂停执行,此时我们可以通过观察变量窗口(显示图形变量及控制变量),调试程序等。

  dev_set_color: 在讲这句的意义之前,我们可以通过HDevelop的菜单栏-》可视化-》颜色  来达到与此句相同的效果,这可能会帮助你理解dev_set_color的意义,其实就是设置图形显示窗口中图形(image,region,xld等)的图像显示颜色。此内部操作和下面讲到的dev_set_colored相辅相成。调试非常有用。

  dev_set_colored:和上面一样,我们可以通过HDevelop的菜单栏-》可视化-》彩色数量  来达到与此句相同的效果。在我们调试程序时,通过connection算子处理后,求取region的连通域,将region分成各不同的region块,即可以通过此功能完成对各region着不同的颜色,方便我们调试、观察。

  dev_set_line_width:和上面一样,可以通过HDevelop的菜单栏-》可视化-》线宽来设置线条的宽度,调试用,比如观察xld时。

  dev_continue_message:在图形窗口上显示继续信息

  Halcon的内部操作暂时讲这么多。至于算子和外部函数稍的再讲 by xiejl

 
原文地址:https://www.cnblogs.com/xiejiulong/p/3817868.html