Results¶
RecognizedText
dataclass
¶
Recognized text class
This class represents a result from a text recognition model.
Attributes:
Name | Type | Description |
---|---|---|
texts |
list[str]
|
A sequence of candidate texts |
scores |
list[float]
|
The scores of the candidate texts |
Source code in src/htrflow_core/results.py
top_candidate()
¶
Result
¶
A result from an arbitrary model (or process)
One result instance corresponds to one input image.
Attributes:
Name | Type | Description |
---|---|---|
metadata |
Metadata regarding the result, model-dependent. |
|
segments |
|
|
data |
Any other data associated with the result, stored as a
sequence of dictionaries. Is assumed to correspond one-to-one
with |
Source code in src/htrflow_core/results.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
bboxes: Sequence[Bbox]
property
¶
Bounding boxes relative to input image
class_labels: Sequence[str | None]
property
¶
Class labels of segments
global_masks: Sequence[Mask | None]
property
¶
Global masks relative to input image
local_mask: Sequence[Mask | None]
property
¶
Local masks relative to bounding boxes
polygons: Sequence[Polygon | None]
property
¶
Polygons relative to input image
drop_indices(index)
¶
Drop segments from result
Example: Given a Result
with three segments s0, s1 and s2,
index = [0, 2] will drop segments s0 and s2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
Sequence[int]
|
Indices of segments to drop |
required |
Source code in src/htrflow_core/results.py
filter(key, predicate)
¶
Filter segments and data based on a predicate applied to a specified key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
The key in the data dictionary to test the predicate against. |
required |
predicate |
[Callable]
|
A function that takes a value associated with the key |
required |
Example:
>>> def remove_certain_text(text_results):
>>> return text_results != 'lorem'
>>> result.filter('text_results', remove_certain_text)
True
Source code in src/htrflow_core/results.py
reorder(index)
¶
Reorder result
Example: Given a Result
with three segments s0, s1 and s2,
index = [2, 0, 1] will put the segments in order [s2, s0, s1].
Any indices not in index
will be dropped from the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
Sequence[int]
|
A list of indices representing the new ordering. |
required |
Source code in src/htrflow_core/results.py
rescale(factor)
¶
segmentation_result(orig_shape, metadata, bboxes=None, masks=None, polygons=None, scores=None, labels=None)
classmethod
¶
Create a segmentation result
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
The original image |
required | |
metadata |
dict[str, Any]
|
Result metadata |
required |
segments |
The segments |
required |
Returns:
Type | Description |
---|---|
Result
|
A Result instance with the specified data and no texts. |
Source code in src/htrflow_core/results.py
text_recognition_result(metadata, texts, scores)
classmethod
¶
Create a text recognition result
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
dict[str, Any]
|
Result metadata |
required |
text |
The recognized text |
required |
Returns:
Type | Description |
---|---|
Result
|
A Result instance with the specified data and no segments. |
Source code in src/htrflow_core/results.py
Segment
¶
Segment class
Class representing a segment of an image, typically a result from a segmentation model or a detection model.
Attributes:
Name | Type | Description |
---|---|---|
bbox |
Bbox
|
The bounding box of the segment |
mask |
Mask | None
|
The segment's mask, if available. The mask is stored
relative to the bounding box. Use the |
score |
float | None
|
Segment confidence score, if available. |
class_label |
str | None
|
Segment class label, if available. |
polygon |
Polygon | None
|
An approximation of the segment mask, relative to the
original image. If no mask is available, |
orig_shape |
tuple[int, int] | None
|
The shape of the orginal input image. |
Source code in src/htrflow_core/results.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
global_mask: Mask | None
property
¶
The segment mask relative to the original input image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orig_shape |
Pass this argument to use another original shape
than the segment's |
required |
local_mask
property
¶
The segment mask relative to the bounding box (alias for self.mask)
__init__(bbox=None, mask=None, score=None, class_label=None, polygon=None, orig_shape=None)
¶
Create a Segment
instance
A segment can be created from a bounding box, a polygon, a mask or any combination of the three.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox |
tuple[int, int, int, int] | Bbox | None
|
The segment's bounding box, as either a |
None
|
mask |
Mask | None
|
The segment's mask relative to the original input image.
Required if both |
None
|
score |
float | None
|
Segment confidence score. Defaults to None. |
None
|
class_label |
str | None
|
Segment class label. Defaults to None. |
None
|
polygon |
Polygon | Sequence[tuple[int, int]] | None
|
A polygon defining the segment, relative to the input
image. Defaults to None. Required if both |
None
|
orig_shape |
tuple[int, int] | None
|
The shape of the orginal input image. Defaults to None. |
None
|
Source code in src/htrflow_core/results.py
approximate_mask(ratio)
¶
A lower resolution version of the global mask
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ratio |
float
|
Size of approximate mask relative to the original. |
required |
Source code in src/htrflow_core/results.py
rescale(factor)
¶
Rescale the segment's mask, bounding box and polygon by factor