libs.annotate_ROI

Utilities behind annotate_rois(): annotation widget, CLI handling, and small helpers.

class formhtr.libs.annotate_ROI.annotate_ROIs_widget.AnnotateROIsWidget(image, config, display_residuals)[source]

Bases: object

Widget to annotate ROIs on the given template.

process_events(event, x, y, *kwargs)[source]

TODO when click inside a rectangle, select it will require a smarter data structure

draw_regions()[source]

Draw regions. Highligh the selected one.

reset_image()[source]

Start again with empty image.

formhtr.libs.annotate_ROI.cli_inputs.process_cli(widget)[source]

Dispatch keyboard commands for AnnotateROIsWidget.

Parameters:

widget – Instance with navigation and update_content_type / read_varname.

Returns:

None when the user presses q or Esc.

formhtr.libs.annotate_ROI.utils.is_approximately_square(top_left_x, top_left_y, bottom_right_x, bottom_right_y, max_width, max_height, error_percentage=1.0)[source]

Check whether provided rectangle is a square

Parameters:
  • top_left_x (float) – top left corner x-coordinate

  • top_left_y (float) – top left corner y-coordinate

  • bottom_right_x (float) – bottom right corner x-coordinate

  • bottom_right_y (float) – bottom right corner y-coordinate

  • max_width (int) – page width

  • max_height (int) – page height

  • error_percentage (float, optional) – allow error. Defaults to 1.0.

Returns:

True if it is a square

Return type:

bool