Halcon对彩色图像进行背景差法分割图像
*读取背景图像
read_image (BGImage, 'Background.jpg')
*依次读取图像
for Index := 1 to 1 by 1
read_image(Image,'Car'+Index+'.jpg')
sub_image (Image,BGImage, ImageSub, 1, 128)
*提取RGB图像的R、G、B通道
decompose3(ImageSub,R,G,B)
* RGB转换HSV
trans_from_rgb(R,G,B,H,S,V,'hsv')
*对S通道图像进行阈值分割
threshold (S, Regions, 50, 255)
*简单区域处理
closing_circle (Regions, RegionClosing, 3)
fill_up (Regions, RegionFillUp)
connection (RegionFillUp, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5000, 99999)
*显示分割结果
dev_clear_window ()
reduce_domain (Image, SelectedRegions, ImageReduced)
dev_display (ImageReduced)
endfor
分割结果: