zoukankan      html  css  js  c++  java
  • Halcon选择一堆region中面积第N大的region的算法实现

    以下图为例:

    比如我想把面积第2小的那个“小正方形”选择出来,算法代码如下:

    1 read_image (Yuan, 'C:/Users/happy xia/Desktop/yuan.png')
    2 binary_threshold (Yuan, Region, 'max_separability', 'dark', UsedThreshold)
    3 connection (Region, ConnectedRegions)
    4 area_center (ConnectedRegions, Area, Row, Column)
    5 tuple_sort_index (Area, Indices)
    6 Num := |Indices|
    7 select_obj (ConnectedRegions, ObjectSelected, Indices[1] + 1)

    该实现算法的关键是对算子tuple_sort_index意思的理解。

    代码中:

    Area := [420, 12922, 38019, 58, 2033]

    Indices := [3, 0, 4, 1, 2]

    tuple_sort_index (Area, Indices)的意思是:先将Area中各元素按升序排序,然后将排序后的每一个Area分别在原Area元组中的索引放在元组Indices 中。

    [3, 0, 4, 1, 2]的意思是:

    58是Area 中的3号元素(元组索引从0开始)

    420是Area 中的0号元素;

    2033是Area 中的4号元素;

    12922是Area 中的1号元素;

    38019是Area 中的2号元素。

    再看看上面tuple_sort_index算子的意思,可知Indices[1]面积第2小的元素在原Area元组中的索引,即索引是0。由于对于算子select_obj 来说,它的索引是从1开始的。所以Indices[1] + 1 是最终的索引。

    结果图:

    如果要找到面积第二大的,只需将最后一句改为:

    select_obj (ConnectedRegions, ObjectSelected, Indices[Num -2] + 1)

  • 相关阅读:
    hping3 DDOS泛洪攻击
    如何利用kali破解密码
    python 字典数据类型day05
    Cisco Packet Tracer思科模拟器汉化本
    菜鸟入坑pythonday04列表
    python菜鸟入坑day02
    python运行的第一个脚本菜鸟篇
    python整个安装过程+环境变量
    菜鸟入坑python第一节
    01、python基础知识
  • 原文地址:https://www.cnblogs.com/xh6300/p/6417801.html
Copyright © 2011-2022 走看看