Geometry Utils
NumPy polygon geometry helpers for rotated text regions.
expand_quad(quad, ratio)
Grow an ordered rectangle outward by area * ratio / perimeter on every side.
For a rectangle this is exactly the minimum-area rectangle of PaddleOCR's
Vatti-clipping unclip result: a w x h rectangle becomes (w + 2D) x (h + 2D).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
ndarray
|
|
required |
ratio
|
float
|
Non-negative expansion ratio. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: |
min_area_rect(points)
Compute the minimum-area rotated rectangle enclosing a point set.
One rectangle is aligned to each convex-hull edge of SciPy's Qhull hull and the smallest one is kept. Point sets without area, such as a single point or collinear points, get their zero-area axis-aligned bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: |
Raises:
| Type | Description |
|---|---|
ImportError
|
If SciPy, provided by the |
order_quad_clockwise(quad)
Order four points as top-left, top-right, bottom-right, bottom-left.
Matches PaddleOCR's order_points_clockwise [1]: points are split by x-coordinate
into a left pair and a right pair, then each pair is ordered by y-coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
ndarray
|
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: |
reading_order(boxes)
Order boxes into rows top to bottom, then left to right within each row.
Boxes are visited by their top edge. The first box of a row anchors it, and a later box joins only when its vertical overlap with the anchor covers at least half of the taller of the two heights, so a tall sidebar or heading cannot swallow unrelated lines beside it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boxes
|
Sequence[tuple[float, float, float, float]]
|
|
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
list[int]: Indices into |