上善若水

水善利万物而不争
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Halcon探索学习 | 4 区域操作--回形针检测

Posted on 2022-12-03 15:35  董锡振  阅读(224)  评论(0编辑  收藏  举报

 

 

 

 

read_image(Image,'clip') 
*1.图像二值化 被选中的是1 没选中的是0   
threshold (Image, Regions, 10, 84)
*2.连通分割  
connection (Regions, ConnectedRegions)
count_obj (ConnectedRegions, Number)
area_center (ConnectedRegions, Area, Row, Column) 
 
select_shape (ConnectedRegions, SelectedRegions, 'column', 'and', 79.82, 1000)

count_obj (ConnectedRegions, Number)

*  形态学变换 边缘有阴影可以进行腐蚀
*3.占用面积   
fill_up (SelectedRegions, RegionFillUp)
*3.1.腐蚀
erosion_rectangle1 (RegionFillUp, RegionErosion, 1, 1)
*3.2.膨胀
dilation_rectangle1 (RegionErosion, RegionDilation, 1, 1)
count_obj (ConnectedRegions, Number)

*合并
union1 (RegionDilation, RegionUnion)
union2 (RegionDilation, Regions, RegionUnion1)

*减操作 difference (RegionUnion1, SelectedRegions, RegionDifference) 
*相交 intersection (RegionDifference, RegionErosion, RegionIntersection) 
*补集   complement (ConnectedRegions, RegionComplement)
*区域转换 求最小外接椭圆
select_obj (SelectedRegions, ObjectSelected, 1)
shape_trans (ObjectSelected, RegionTrans, 'ellipse')