39、Region按面积大小排序

Halcon中没有现成的Region按面积排序算子,给出以下自定义函数.

   

area_center (Regions, Area, Row, Column)

tuple_sort (Area, Area_sorted)

gen_empty_obj (SortedRegion)

    if (SortMode=0)

        *降序排序

         for Index :=0  to |Area_sorted|-1 by 1

            tuple_find (Area,Area_sorted[|Area_sorted|-1-Index] , Indices)

            select_obj (Regions, SelectedRegion,Indices+1)

            concat_obj (SortedRegion, SelectedRegion, SortedRegion)

        endfor

    else

       *升序排序    

        for Index := 0 to |Area_sorted|-1 by 1

            tuple_find (Area,Area_sorted[Index] , Indices)

            select_obj (Regions, SelectedRegion,Indices+1)

            concat_obj (SortedRegion, SelectedRegion, SortedRegion)

        endfor

    endif 

return ()

   

函数下载: http://pan.baidu.com/s/1o8u5Z9w

posted @ 2022-05-31 23:47  ihh2021  阅读(920)  评论(0编辑  收藏  举报