【问题标题】:How can I select the largest region in HALCON?如何在 HALCON 中选择最大的区域?
【发布时间】:2021-03-09 12:13:55
【问题描述】:

我想从一组区域中选择最大的区域(在本例中为ConnectedRegions)。

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

有什么优雅的方法可以实现这一目标?

【问题讨论】:

    标签: halcon


    【解决方案1】:

    更新答案

    使用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)
    

    【讨论】:

      猜你喜欢
      • 2020-11-18
      • 2020-12-13
      • 2020-10-28
      • 1970-01-01
      • 2020-09-22
      • 2021-01-29
      • 2020-12-23
      • 2020-03-30
      • 2021-01-29
      相关资源
      最近更新 更多