首页 > 解决方案 > 如何在 HALCON 中选择最大的区域?

问题描述

我想从一组区域中选择最大的区域(ConnectedRegions在这种情况下)。

threshold (Image, Region, 250, 255)
connection (Region, ConnectedRegions)
* TODO: Get the largest region in ConnectedRegions

实现这一目标的优雅方法是什么?

标签: halcon

解决方案


更新的答案

使用select_shape_std

select_shape_std (ConnectedRegions, MaxRegion, 'max_area', 0)

对于其他选择标准,有select_shape

原始答案

使用三个运算符,您可以解决示例中的任务area_centertuple_sort_indexselect_obj

threshold (Image, Region, 250, 255)
connection (Region, ConnectedRegions)

* Get the area of each region. R and C return values are not used.
area_center (ConnectedRegions, Areas, R, C)

* Get the indices to sort the areas in descending order.
tuple_sort_index (- Areas, SortIndices)

* Select the region using the first index.
* We need to add 1, because control tuples use 0-based indexing,
* while object tuples are 1-based
select_obj (ConnectedRegions, MaxRegion, SortIndices[0] + 1)

推荐阅读