将药片分割,统计药片数量。不能使用模板匹配。
read_image (Image913810Afb2e0c19469408, 'C:/Users/Administrator/Desktop/10_34706_aeb91e22c49d25f.bmp')
dev_set_draw ('margin')
get_image_size(Image913810Afb2e0c19469408, Width, Height)
threshold(Image913810Afb2e0c19469408, Region, 0, 100)
erosion_circle(Region, RegionErosion, 4.5)
opening_circle(RegionErosion, RegionOpening3, 1.5)
connection(RegionOpening3, ConnectedRegions1)
*第一部分
select_shape(ConnectedRegions1, SelectedRegions, ['area','rectangularity'], 'and', [100,0.5], [700,1])
dilation_circle(SelectedRegions, RegionDilation, 4.5)
difference(ConnectedRegions1, SelectedRegions, SelectedRegions1)
gen_empty_obj(ObjectsConcat)
concat_obj(RegionDilation, ObjectsConcat, ObjectsConcat)
*第二部分循环分割
for Index := 1 to 10 by 1
shape_trans (SelectedRegions1, RegionTrans, 'convex')
difference (RegionTrans, SelectedRegions1, RegionDifference)
opening_circle(RegionDifference, RegionOpening1, 3.5)
closing_circle (RegionOpening1, RegionClosing, 30.5)
difference (SelectedRegions1, RegionClosing, RegionDifference1)
connection (RegionDifference1, ConnectedRegions)
select_shape(ConnectedRegions, SelectedRegions6, 'area', 'and', 100, 700)
gen_empty_obj(RegionDilation1)
dilation_circle(SelectedRegions6, RegionDilation1, 4.5)
concat_obj(RegionDilation1, ObjectsConcat, ObjectsConcat)
difference (SelectedRegions1, RegionDilation1, RegionDifference2)
select_shape(RegionDifference2, SelectedRegions2, 'area', 'and', 100, 700)
dilation_circle(SelectedRegions2, RegionDilation2, 4.5)
concat_obj(ObjectsConcat, RegionDilation2, ObjectsConcat)
select_shape(RegionDifference2, SelectedRegions1, 'area', 'and', 700, 99999)
count_obj(SelectedRegions1, Num)
if(Num==0)
break
endif
endfor
select_shape(ObjectsConcat,SelectedRegions5, 'area', 'and', 200, 99999)
area_center (SelectedRegions5, Area1, Row1, Column1)
gen_cross_contour_xld (Cross, Row1, Column1, 10, 0.785398)
dev_display (Image913810Afb2e0c19469408)
dev_display (Cross)