本例程来自halcon例程中的Blob分析中的autobahn例程
通过此例程可以很好的掌握sobel_amp算子的使用。详细使用请查看halcon算子说明文档
例程耿总目标的基本思路:
先获得主要感兴趣区域,去除车的干扰
然后通过sobel_amp算子检测边缘明显变化的图像,得到原始图像边缘位置的图像数据
然后通过阈值获取目标边缘。
通过膨胀目标边缘获得感兴趣区域,再次通过阈值分割获得目标
原始例程如下:
* autobahn.hdev: Fast detection of lane markers
*
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 768, 575, 'black', WindowID)
MinSize := 30
get_system ('init_new_image', Information)
set_system ('init_new_image', 'false')
gen_grid_region (Grid, MinSize, MinSize, 'lines', 512, 512)
clip_region (Grid, StreetGrid, 130, 10, 450, 502)
dev_set_line_width (3)
dev_set_color ('green')
read_image (ActualImage, 'autobahn/scene_00')
dev_display (ActualImage)
stop ()
dev_display (StreetGrid)
stop ()
for i := 0 to 28 by 1
read_image (ActualImage, 'autobahn/scene_'+(i$'02'))
reduce_domain (ActualImage, StreetGrid, Mask)
dev_clear_window ()
dev_display(StreetGrid)
dev_clear_window ()
dev_display(Mask)
sobel_amp (Mask, Gradient, 'sum_abs', 3)
threshold (Gradient, Points, 20, 255)
dilation_rectangle1 (Points, RegionDilation, MinSize, MinSize)
reduce_domain (ActualImage, RegionDilation, StripGray)
threshold (StripGray, Strip, 190, 255)
fill_up (Strip, RegionFillUp)
dev_display (ActualImage)
dev_display (RegionFillUp)
endfor
dev_set_line_width (1)
dev_update_window ('on')
set_system ('init_new_image', Information)
经过分析,修改后的分析方法程序如下:
* autobahn.hdev: Fast detection of lane markers
*
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 768, 575, 'black', WindowID)
MinSize := 30
get_system ('init_new_image', Information)
set_system ('init_new_image', 'false')
dev_set_line_width (3)
dev_set_color ('green')
stop ()
for i := 0 to 28 by 1
read_image (ActualImage, 'autobahn/scene_'+(i$'02'))
gen_rectangle1 (Rectangle, 130, 0, 512, 512)
reduce_domain (ActualImage, Rectangle, ReduceImage)
sobel_amp (ReduceImage, Amp, 'sum_abs', 3)
threshold (Amp, Points, 20, 255)
dilation_rectangle1 (Points, RegionDilation, MinSize, MinSize)
reduce_domain (ActualImage, RegionDilation, StripGray)
threshold (StripGray, Strip, 190, 255)
fill_up (Strip, RegionFillUp)
dev_display (ActualImage)
dev_display (RegionFillUp)
stop()
endfor
dev_set_line_width (1)
dev_update_window ('on')
set_system ('init_new_image', Information)