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 ()