Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions labeler/automation/auto_labeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import cv2
import numpy as np
import onnxruntime as ort
from onnxtr.io import DocumentFile
from onnxtr.models import from_hub, ocr_predictor

ort.set_default_logger_severity(os.getenv("ORT_LOG_SEVERITY_LEVEL", 4))

from ..logger import logger

__all__ = ["AutoLabeler"]
Expand Down
6 changes: 6 additions & 0 deletions labeler/views/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@

def zoom(self, event: Event | None = None):
"""Handle zooming in and out."""
# NOTE: The zoom functionality is disabled while drawing a polygon
# because it can cause scale issues with the polygon points.
if self.drawing_polygon:
logger.info("Cannot zoom while drawing a polygon")
return

Check warning on line 64 in labeler/views/canvas.py

View check run for this annotation

Codecov / codecov/patch

labeler/views/canvas.py#L62-L64

Added lines #L62 - L64 were not covered by tests

zoom_step = 0.1 # Zoom step size
max_zoom = min(float(os.environ.get("DOCTR_LABELER_MAX_ZOOM", 1.5)), 2.0) # Maximum zoom capped at 2.0
min_zoom = max(float(os.environ.get("DOCTR_LABELER_MIN_ZOOM", 0.5)), 0.1) # Minimum zoom capped at 0.1
Expand Down
19 changes: 11 additions & 8 deletions labeler/views/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
self.type_variable = tk.StringVar(self.top_frame, self.type_options[0])
# Listener for label type
self.type_variable.trace_add("write", lambda *args: self.save_type())
self.label_type = ttk.OptionMenu(
self.top_frame, self.type_variable, self.type_variable.get(), *self.type_options
self.label_type = ttk.Combobox(
self.top_frame, textvariable=self.type_variable, values=self.type_options, state="readonly"
)
self.progress_bar = ttk.Progressbar(self.top_frame, orient="horizontal", length=100, mode="determinate")

Expand Down Expand Up @@ -311,7 +311,7 @@
self.draw_poly_button.configure(state="normal")
self.make_tight_button.configure(state="normal")
self.label_text.configure(state="normal")
self.label_type.configure(state="normal")
self.label_type.configure(state="readonly")

def select_all(self, event: tk.Event | None = None):
"""
Expand Down Expand Up @@ -351,13 +351,15 @@
if not self.img_cnv or not hasattr(self, "last_selected_polygon"):
return

last_selected_polygon = next(
(poly for poly in self.img_cnv.polygons if poly.polygon_id == self.last_selected_polygon), None
)
if last_selected_polygon and last_selected_polygon.select_poly:
selected_polys = [poly for poly in self.img_cnv.polygons if poly.select_poly]
if selected_polys:
with self.img_cnv.polygons_mutex:
new_type = self.type_variable.get().strip()
last_selected_polygon.poly_type = new_type
# skip if it's the default type
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t2k-list otherwise we override prev selected with the default

if new_type == self.type_options[0]:
return

Check warning on line 360 in labeler/views/gui.py

View check run for this annotation

Codecov / codecov/patch

labeler/views/gui.py#L360

Added line #L360 was not covered by tests
for poly in selected_polys:
poly.poly_type = new_type
self.img_cnv.current_saved = False
self.save_image_button.configure(state="normal")

Expand Down Expand Up @@ -566,6 +568,7 @@
"""
Save the annotations for the image
"""
self.deselect_all()
logger.info(f"Saving annotations for {self.image_name}")
self.save_image_button.configure(state="disabled")
saving_path = self.img_cnv.save_json() # type: ignore[union-attr]
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module = [
"darkdetect.*",
"tqdm.*",
"huggingface_hub.*",
"onnxruntime.*",
"onnxtr.*",
]
ignore_missing_imports = true
Expand All @@ -131,6 +132,8 @@ known-third-party = [
"tkinter",
"sv_ttk",
"darkdetect",
"onnxruntime",
"onnxtr",
]

[tool.ruff.lint.per-file-ignores]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup

PKG_NAME = "doctr-labeler"
VERSION = os.getenv("BUILD_VERSION", "0.1.5a0")
VERSION = os.getenv("BUILD_VERSION", "0.1.6a0")


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions tests/common/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_show_buttons(gui_app):
assert str(gui_app.draw_poly_button["state"]) == "normal"
assert str(gui_app.make_tight_button["state"]) == "normal"
assert str(gui_app.label_text["state"]) == "normal"
assert str(gui_app.label_type["state"]) == "normal"
assert str(gui_app.label_type["state"]) == "readonly"


def test_toggle_keep_drawing(gui_app):
Expand Down Expand Up @@ -151,10 +151,10 @@ def test_show_buttons_enables_buttons(gui_app):
gui_app.draw_poly_button,
gui_app.make_tight_button,
gui_app.label_text,
gui_app.label_type,
]
for button in buttons:
assert str(button["state"]) == "normal"
assert str(gui_app.label_type["state"]) == "readonly"


def test_select_all(gui_app):
Expand Down Expand Up @@ -338,11 +338,11 @@ def test_delete_selected(gui_app):
gui_app.save_image_button.configure.assert_called_once_with(state="normal")


def test_saver(gui_app):
def test_saver(gui_app, monkeypatch):
gui_app.img_cnv = Mock()
gui_app.img_cnv.save_json.return_value = "test_path"
gui_app.save_image_button = Mock()

monkeypatch.setattr(gui_app, "deselect_all", lambda: None)
with patch("labeler.views.gui.logger") as mock_logger:
gui_app.saver()

Expand Down