halcon-clip.hdev

* clip.hdev: Orientation of clips
* 
dev_update_window ('off')
read_image (Clip, 'clip')
get_image_size (Clip, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width/2, Height/2, 'black', WindowID)
dev_display (Clip)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
bin_threshold (Clip, Dark)
connection (Dark, Single)
select_shape (Single, Selected, 'area', 'and', 5000, 10000)
dev_set_draw ('fill')
dev_set_colored (12)
dev_display (Selected)
disp_continue_message (WindowID, 'black', 'true')
stop ()
dev_display (Clip)
dev_set_color ('green')
dev_display (Selected)
orientation_region (Selected, Phi)
area_center (Selected, Area, Row, Column)
dev_set_line_width (3)
dev_set_draw ('margin')
Length := 80
for i := 0 to |Phi|-1 by 1
    dev_set_color ('blue')
    disp_arrow (WindowID, Row[i], Column[i], Row[i]-Length*sin(Phi[i]), Column[i]+Length*cos(Phi[i]), 4)
    disp_message (WindowID, deg(Phi[i])$'3.1f'+' deg', 'image', Row[i], Column[i]-100, 'black', 'false')
endfor
dev_update_window ('on')


 
Clip是一个灰度图像

bin_threshold (Clip, Dark)
自动阈值,输出为一个区域
也可以使用灰度直方图工具手动尝试确定阈值范围

connection (Dark, Single)
区域链接,输出是区域元组


select_shape (Single, Selected, 'area', 'and', 5000, 10000)
选择面积是5000到10000之间的区域,输出是区域元组
可以使用特征直方图手动尝试确定面积范围

orientation_region (Selected, Phi)
求方向,根据一个区域的最远点和最近点确定方向

area_center (Selected, Area, Row, Column)
求区域的面积和中心点。selected可以是一个区域也可以是一个区域元组(tuple,即数组)

本例基本步骤:
1.输入灰度图像
2.bin_threshold,自动阈值成二值图像
3.connection,区域链接生成区域元组
4.select_shape,挑选出元组中符合一定条件的区域
5.orientation_region,求元组中各个区域的方向
6.area_center,求元组中各个区域的面积和中心点
posted on 2012-09-05 21:15  _song  阅读(526)  评论(0编辑  收藏  举报