HALCON示例程序IC.hdev通过电路板元器件定位识别
示例程序源码(加注释)
- 关于显示类函数解释
dev_close_window ()
read_image (Image, ‘ic’)
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, ‘black’, WindowID)
dev_set_draw (‘fill’)
dev_set_part (0, 0, Height - 1, Width - 1)
dev_display (Image)
dev_set_colored (12) - RGB图像分为三个通道名之后进行空间转换,转换至HSV空间
decompose3 (Image, Red, Green, Blue)
trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, ‘hsv’) - 二值化
threshold (Saturation, Colored, 100, 255) - 减少定义域
reduce_domain (Hue, Colored, HueColored) - 二值化
threshold (HueColored, Red, 10, 19) - 分割连通域
connection (Red, RedConnect) - 使用面积筛选区域
select_shape (RedConnect, RedLarge, ‘area’, ‘and’, 150.000000, 99999.000000) - 对区域进行形状转化,装换位最小可旋转外接矩形
shape_trans (RedLarge, Resistors, ‘rectangle2’) - 二值化
threshold (HueColored, Blue, 114, 137) - 分割连通域
connection (Blue, BlueConnect) - 使用面积筛选区域
select_shape (BlueConnect, BlueLarge, ‘area’, ‘and’, 150.000000, 99999.000000) - 对区域进行形状转化,装换位最小可旋转外接矩形
shape_trans (BlueLarge, Capacitors, ‘rectangle2’) - 二值化
threshold (Intensity, Dark, 0, 50) - 使用矩形元素膨胀区域
dilation_rectangle1 (Dark, DarkDilation, 14, 14) - 分割连通域
connection (DarkDilation, ICLarge) - 向区域添加灰度值
add_channels (ICLarge, Intensity, ICLargeGray) - 二值化
threshold (ICLargeGray, ICDark, 0, 50) - 对区域进行形状转化,装换位最小可旋转外接矩形
shape_trans (ICDark, IC, ‘rectangle2’) - 使用矩形元素膨胀区域
dilation_rectangle1 (IC, ICDilation, 5, 1) - 求取两区域不相交区域
difference (ICDilation, IC, SearchSpace) - 使用矩形元素膨胀区域
dilation_rectangle1 (SearchSpace, SearchSpaceDilation, 14, 1) - 合并区域
union1 (SearchSpaceDilation, SearchSpaceUnion) - 减少定义域
reduce_domain (Intensity, SearchSpaceUnion, SearchGray) - 动态阈值分割图像
mean_image (SearchGray, SearchMean, 15, 15)
dyn_threshold (SearchGray, SearchMean, PinsRaw, 5.000000, ‘light’) - 分割连通域
connection (PinsRaw, PinsConnect) - 填充孔洞
fill_up (PinsConnect, PinsFilled) - 使用面积筛选区域
select_shape (PinsFilled, Pins, ‘area’, ‘and’, 10, 100)
dev_display (Image)
dev_set_draw (‘margin’)
dev_set_line_width (3)
dev_set_color (‘red’)
dev_display (IC)
dev_set_color (‘green’)
dev_display (Resistors)
dev_set_color (‘blue’)
dev_display (Capacitors)
dev_set_color (‘yellow’)
dev_display (Pins)
处理思路
这个例子是主要进行了简单的blob分析。使用到了add_channels 、trans_from_rgb、dilation_rectangle1 、shape_trans 、dyn_threshold 等算子。
后记
大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。