Halcon实战案例之硅胶线颜色寻找(阈值分割)

寻找出各个硅胶线的颜色

read_image (Image, 'cable1')
*获取窗口句柄
dev_get_window (WindowHandle)
*获取3图像中的每个通道的图像 红绿蓝
decompose3 (Image, R, G, B)
*将RGB三通道数据转化为hsv色彩空间图像数据 h色点 s饱和度 v亮度
trans_from_rgb (R, G, B, H, S, V, 'hsv')
*第三个
*找到一个合适的图像进行阈值分割
threshold (S, Region, 190, 255)
*连通域处理
connection (Region, ConnectedRegions)
*找到最大的区域
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)
*填充细小空洞
closing_circle (SelectedRegions, RegionClosing, 3.5)
area_center (RegionClosing, Area, Row, Column)

*第一个
*阈值分割
threshold (R, Region1, 0, 50)
*连通域处理
connection (Region1, ConnectedRegions1)
*找到最大的区域
select_shape_std (ConnectedRegions1, SelectedRegions1, 'max_area', 70)
*填充细小空洞
closing_circle (SelectedRegions1, RegionClosing1, 3.5)
area_center (RegionClosing1, Area1, Row1, Column1)
*第二个
*阈值分割
threshold (R, Region2, 50, 100)
*连通域处理
connection (Region2, ConnectedRegions2)
*找到最大的区域
select_shape_std (ConnectedRegions2, SelectedRegions2, 'max_area', 70)
*填充细小空洞
closing_circle (SelectedRegions2, RegionClosing2, 3.5)
area_center (RegionClosing2, Area2, Row2, Column2)
*第五个
*阈值分割
threshold (S, Region3, 150, 255)
*剪切出想要的区域
reduce_domain (H, Region3, ImageReduced)
*阈值分割
threshold (ImageReduced, Region4, 20, 50)
*连通域处理
connection (Region4, ConnectedRegions3)
*找到最大的区域
select_shape_std (ConnectedRegions3, SelectedRegions3, 'max_area', 70)
*填充细小空洞
closing_circle (SelectedRegions3, RegionClosing3, 3.5)
area_center (RegionClosing3, Area3, Row3, Column3)
*第四个
*合并第三条线和第五条线
union2 (RegionClosing, RegionClosing3, RegionUnion)
*找到补集
difference (ImageReduced, RegionUnion, RegionDifference)
*连通域处理
connection (RegionDifference, ConnectedRegions4)
*找到最大的区域
select_shape_std (ConnectedRegions4, SelectedRegions4, 'max_area', 70)
*填充细小空洞
closing_circle (SelectedRegions4, RegionClosing4, 3.5)
area_center (RegionClosing4, Area4, Row4, Column4)
dev_display(Image)
set_display_font (WindowHandle, 12, 'mono', 'true', 'false')
set_tposition (WindowHandle, Row, Column)
write_string (WindowHandle, '红色')
set_tposition (WindowHandle, Row1, Column1)
write_string (WindowHandle, '黑色')
set_tposition (WindowHandle, Row2, Column2)
write_string (WindowHandle, '棕色')
set_tposition (WindowHandle, Row3, Column3)
write_string (WindowHandle, '黄色')
set_tposition (WindowHandle, Row4, Column4)
write_string (WindowHandle, '橙色')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值