Operator Reference

sort_regionsort_regionSortRegionSortRegionsort_region (Operator)

sort_regionsort_regionSortRegionSortRegionsort_region — Sorting of regions with respect to their relative position.

Signature

sort_region(Regions : SortedRegions : SortMode, Order, RowOrCol : )

Herror sort_region(const Hobject Regions, Hobject* SortedRegions, const char* SortMode, const char* Order, const char* RowOrCol)

Herror T_sort_region(const Hobject Regions, Hobject* SortedRegions, const Htuple SortMode, const Htuple Order, const Htuple RowOrCol)

void SortRegion(const HObject& Regions, HObject* SortedRegions, const HTuple& SortMode, const HTuple& Order, const HTuple& RowOrCol)

HRegion HRegion::SortRegion(const HTuple& SortMode, const HString& Order, const HString& RowOrCol) const

HRegion HRegion::SortRegion(const HTuple& SortMode, const char* Order, const char* RowOrCol) const

HRegion HRegion::SortRegion(const HTuple& SortMode, const wchar_t* Order, const wchar_t* RowOrCol) const   ( Windows only)

static void HOperatorSet.SortRegion(HObject regions, out HObject sortedRegions, HTuple sortMode, HTuple order, HTuple rowOrCol)

HRegion HRegion.SortRegion(HTuple sortMode, string order, string rowOrCol)

def sort_region(regions: HObject, sort_mode: MaybeSequence[Union[int, float, str]], order: str, row_or_col: str) -> HObject

Description

The operator sort_regionsort_regionSortRegionSortRegionsort_region sorts the regions with respect to their relative position. All sorting methods with the exception of 'character'"character""character""character""character" use one point of the region. With the help of the parameter RowOrColRowOrColRowOrColrowOrColrow_or_col = 'row'"row""row""row""row" these points will be sorted according to their row and then according to their column. By using 'column'"column""column""column""column", the column value will be used first. The following values are available for the parameter SortModeSortModeSortModesortModesort_mode:

'character'"character""character""character""character"

The regions are treated like characters, which can be read horizontally or vertically. They are sorted according to the reading direction given by RowOrColRowOrColRowOrColrowOrColrow_or_col with the following specifications:

  • 'row'"row""row""row""row": Regarded as rows, the reading direction is firstly from left to right and then from top to bottom.

  • 'column'"column""column""column""column": Regarded as columns, the reading direction is firstly from top to bottom and then from left to right.

For SortModeSortModeSortModesortModesort_mode 'character'"character""character""character""character", a second numeric value can be passed to SortModeSortModeSortModesortModesort_mode in addition to 'character'"character""character""character""character". This value specifies the maximum percentage of overlap. This overlap depends on the parameter RowOrColRowOrColRowOrColrowOrColrow_or_col and is determined as follows:

whereas the percentage of overlap is calculated using the smaller one of the overlapping regions (with respect to the specified axis). Regions that do not overlap in their coordinates or have an overlap of less than the set percentage are seen as being in different rows (or columns, respectively) and sorted accordingly. In case the overlap is larger, the regions are seen as being in the same row (or column) instead and therefore sorted within the row (or column). For example when this additional parameter is set to 0, all regions that overlap in their row (or column) coordinates are sorted within the same row (or column). The default value of this parameter is 15 which means that adjacent rows (or columns) can have an overlap of maximum 15% in order to be considered as different rows (or columns). Note that for OrderOrderOrderorderorder = 'false'"false""false""false""false", the characters are sorted in a reversed order to the one described above.

'first_point'"first_point""first_point""first_point""first_point"

The point with the lowest column value in the first row of the region.

'last_point'"last_point""last_point""last_point""last_point"

The point with the highest column value in the last row of the region.

'upper_left'"upper_left""upper_left""upper_left""upper_left"

Upper left corner of the surrounding rectangle.

'upper_right'"upper_right""upper_right""upper_right""upper_right"

Upper right corner of the surrounding rectangle.

'lower_left'"lower_left""lower_left""lower_left""lower_left"

Lower left corner of the surrounding rectangle.

'lower_right'"lower_right""lower_right""lower_right""lower_right"

Lower right corner of the surrounding rectangle.

The parameter OrderOrderOrderorderorder determines whether the sorting order is increasing or decreasing: using 'true'"true""true""true""true" the order will be increasing, using 'false'"false""false""false""false" the order will be decreasing.

Execution Information

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Processed without parallelization.

Parameters

RegionsRegionsRegionsregionsregions (input_object)  region-array objectHRegionHObjectHObjectHobject

Regions to be sorted.

SortedRegionsSortedRegionsSortedRegionssortedRegionssorted_regions (output_object)  region-array objectHRegionHObjectHObjectHobject *

Sorted regions.

SortModeSortModeSortModesortModesort_mode (input_control)  tuple(-array) HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)

Kind of sorting.

Default: 'first_point' "first_point" "first_point" "first_point" "first_point"

List of values: 'character'"character""character""character""character", 'first_point'"first_point""first_point""first_point""first_point", 'last_point'"last_point""last_point""last_point""last_point", 'lower_left'"lower_left""lower_left""lower_left""lower_left", 'lower_right'"lower_right""lower_right""lower_right""lower_right", 'upper_left'"upper_left""upper_left""upper_left""upper_left", 'upper_right'"upper_right""upper_right""upper_right""upper_right"

OrderOrderOrderorderorder (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Increasing or decreasing sorting order.

Default: 'true' "true" "true" "true" "true"

List of values: 'false'"false""false""false""false", 'true'"true""true""true""true"

RowOrColRowOrColRowOrColrowOrColrow_or_col (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Sorting first with respect to row, then to column.

Default: 'row' "row" "row" "row" "row"

List of values: 'column'"column""column""column""column", 'row'"row""row""row""row"

Result

If the parameters are correct, the operator sort_regionsort_regionSortRegionSortRegionsort_region returns the value 2 ( H_MSG_TRUE) . Otherwise an exception will be raised.

Possible Successors

do_ocr_multi_class_mlpdo_ocr_multi_class_mlpDoOcrMultiClassMlpDoOcrMultiClassMlpdo_ocr_multi_class_mlp, do_ocr_single_class_mlpdo_ocr_single_class_mlpDoOcrSingleClassMlpDoOcrSingleClassMlpdo_ocr_single_class_mlp

Module

Foundation