该样例主要功能是检测一个鱼鳍状的特征区域,如下图:
原码
1 * fin.hdev: Detection of a fin 2 * 3 dev_update_window ('off') 4 read_image (Fin, 'fin1') 5 get_image_size (Fin, Width, Height) 6 dev_close_window () 7 dev_open_window (0, 0, Width, Height, 'black', WindowID) 8 dev_display (Fin) 9 set_display_font (WindowID, 14, 'mono', 'true', 'false') 10 disp_continue_message (WindowID, 'black', 'true') 11 stop () 12 * read_image (Fin, 'fin2') 13 * read_image (Fin, 'fin3') 14 bin_threshold (Fin, Dark) 15 difference (Fin, Dark, Background) 16 dev_set_color ('blue') 17 dev_set_draw ('margin') 18 dev_set_line_width (4) 19 dev_display (Background) 20 disp_continue_message (WindowID, 'black', 'true') 21 stop () 22 closing_circle (Background, ClosedBackground, 250) 23 dev_set_color ('green') 24 dev_display (ClosedBackground) 25 disp_continue_message (WindowID, 'black', 'true') 26 stop () 27 difference (ClosedBackground, Background, RegionDifference) 28 opening_rectangle1 (RegionDifference, FinRegion, 5, 5) 29 dev_display (Fin) 30 dev_set_color ('red') 31 dev_display (FinRegion) 32 area_center (FinRegion, FinArea, Row, Column) 33 dev_set_draw ('fill') 34 dev_set_line_width (1) 35 dev_update_window ('on') 36 disp_continue_message (WindowID, 'black', 'true') 37 stop () 38 dev_close_window ()
核心算子
-
bin_threshold (Fin, Dark) //对单通道图像进行自动二值化,阈值根据图像灰度值分布自动确定。输出为暗区域。
-
difference (Fin, Dark, Background) //比较两个区域,输入不同的部分。
-
bin_threshold (Fin, Dark) //对单通道图像进行自动二值化,阈值根据图像灰度值分布自动确定。输出为暗区域。
-
closing_circle (Background, ClosedBackground, 250) //对区域的边缘进行平滑处理,边缘上小于参数中半径的坑洞都会被填平。
-
opening_rectangle1 (RegionDifference, FinRegion, 5, 5) //按照参数里设置的宽和高,大的区域保留,小的区域过滤掉。