需要留意,是用模板减去图像,可能会有一些像素为负值,还需要反过来再求一次sub_image ,把两次的求和才好。
read_image (Template, 'D:/Project/Halcon/rgb_template.png')
read_image (Image, 'D:/Project/Halcon/rgb_test4.png')
*若统计不同,需要再反向再做一次,即调换Template和Image的位置
sub_image (Template,Image,ImageSub, 1, 255)
rgb1_to_gray (ImageSub, GrayImage)
threshold (GrayImage, Region, 0, 254)
*套路步骤
connection (Region, ConnectedRegions)
*统计个数
count_obj (ConnectedRegions, Number)
*统计面积
area_center (ConnectedRegions, Area, Row, Column)
tuple_sum (Area, SumDiffArea)
get_image_size (Template, Width, Height)
TotalArea:=Width*Height
percent:=(TotalArea-SumDiffArea)*1.0/TotalArea*100