1.算子
计算区域的圆度
circularity(Regions : : : Circularity)
应用范围:
- 圆形物体检测,区域剔除
2.理论
其中,C:圆度;F:区域面积;max:区域中心到轮廓点的最大值
3.代码
* Calculate the shape factor for the roundness of regions.
*
read_image (Image, 'fabrik')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowID)
dev_set_color ('white')
dev_set_draw ('fill')
* Segment an image using region growing
regiongrowing (Image, Regions, 1, 1, 3, 100)
count_obj (Regions, Number)
* Display regions - if circularity > 0.4, use green color, else use red colour
for i := 1 to Number by 1
select_obj (Regions, ObjectSelected, i)
circularity (ObjectSelected, Circularity)
if (Circularity > 0.4)
dev_set_color ('green')
dev_display (ObjectSelected)
else
dev_set_color ('red')
dev_display (ObjectSelected)
endif
endfor
stop ()
* Now faster
dev_set_color ('red')
* Select regions by checking their circularity
select_shape (Regions, SelectedRegions1, 'circularity', 'and', 0, 0.4)
dev_set_color ('green')
select_shape (Regions, SelectedRegions2, 'circularity', 'and', 0.4, 1)
4.结果
5.参考
* Halcon官方帮助文档