*关闭已经打开的窗口
dev_close_window ()
*打开新窗口
dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
for i := 1 to 2 by 1
*打开一张图像
read_image (Image, 'cable' + i)
*获取一个三通道图像里的每个通道的图像数据
decompose3 (Image, Red, Green, Blue)
*将RGB三通道数据转化为HSV色彩空间的三通道图像数据
trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv')
对HSV图像中的饱和度通道进行阈值操作
threshold (Saturation, HighSaturation, 100, 255)
*获取上述阈值操作后区域中的色调通道图像数据
reduce_domain (Hue, HighSaturation, HueHighSaturation)
*对上述色调通道图像数据进行阈值处理
threshold (HueHighSaturation, Yellow, 20, 50)
*获取区域里连接的组件
connection (Yellow, ConnectedRegions)
*保留ConnectedRegions里的最大的区域
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 0)
*对SelectedRegions进行闭运算操作
closing_circle (SelectedRegions, Yellow, 3.5)
*将Yellow区域里的图像剪切出来
reduce_domain (Image, Yellow, ImageReduced)
*显示图像
dev_clear_window()
dev_set_color ('white')
dev_set_draw ('margin')
*显示黄色的电线
dev_display (Image)
dev_display (Yellow)
stop ()
endfor
Halcon 根据颜色来提取想要的目标对象
最新推荐文章于 2024-07-08 11:38:25 发布