MCPcopy Create free account
hub / github.com/mindee/doctr / create_obj_patch

Function create_obj_patch

doctr/utils/visualization.py:112–134  ·  view source on GitHub ↗

Create a matplotlib patch for the element Args: geometry: bounding box (straight or rotated) of the element page_dimensions: dimensions of the page in format (height, width) **kwargs: keyword arguments for the patch Returns: a matplotlib Patch

(
    geometry: BoundingBox | Polygon4P | np.ndarray,
    page_dimensions: tuple[int, int],
    **kwargs: Any,
)

Source from the content-addressed store, hash-verified

110
111
112def create_obj_patch(
113 geometry: BoundingBox | Polygon4P | np.ndarray,
114 page_dimensions: tuple[int, int],
115 **kwargs: Any,
116) -> patches.Patch:
117 """Create a matplotlib patch for the element
118
119 Args:
120 geometry: bounding box (straight or rotated) of the element
121 page_dimensions: dimensions of the page in format (height, width)
122 **kwargs: keyword arguments for the patch
123
124 Returns:
125 a matplotlib Patch
126 """
127 if isinstance(geometry, tuple):
128 if len(geometry) == 2: # straight word BB (2 pts)
129 return rect_patch(geometry, page_dimensions, **kwargs)
130 elif len(geometry) == 4: # rotated word BB (4 pts)
131 return polygon_patch(np.asarray(geometry), page_dimensions, **kwargs)
132 elif isinstance(geometry, np.ndarray) and geometry.shape == (4, 2): # rotated line
133 return polygon_patch(geometry, page_dimensions, **kwargs)
134 raise ValueError("invalid geometry format")
135
136
137def get_colors(num_colors: int) -> list[tuple[float, float, float]]:

Callers 2

visualize_pageFunction · 0.85
visualize_kie_pageFunction · 0.85

Calls 2

rect_patchFunction · 0.85
polygon_patchFunction · 0.85

Tested by

no test coverage detected