Results¶
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 |
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. |
Create a Result
See also the alternative constructors Result.text_recognition_result, Result.segmentation_result and Result.word_segmentation_result.
Source code in src/htrflow/results.py
bboxes
property
¶
Bounding boxes relative to input image
class_labels
property
¶
Class labels of segments
global_masks
property
¶
Global masks relative to input image
local_mask
property
¶
Local masks relative to bounding boxes
polygons
property
¶
Polygons relative to input image
drop_indices
¶
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/results.py
filter
¶
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/results.py
reorder
¶
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/results.py
rescale
¶
segmentation_result
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/results.py
text_recognition_result
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/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. |
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/results.py
global_mask
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)
approximate_mask
¶
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/results.py
rescale
¶
Rescale the segment's mask, bounding box and polygon by factor