Skip to content

Commit

Permalink
[Feature] Add system_clipboard copy mode
Browse files Browse the repository at this point in the history
By the way, the code for serializing the Shape class was refactored.
  • Loading branch information
PairZhu committed Jun 30, 2024
1 parent 3e5ff5c commit 24d14f2
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 167 deletions.
1 change: 1 addition & 0 deletions anylabeling/configs/xanylabeling_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ show_degrees: false
show_shapes: true
logger_level: info
save_mode: default
system_clipboard: false

flags: null
label_flags: null
Expand Down
44 changes: 8 additions & 36 deletions anylabeling/views/labeling/label_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ...app_info import __version__
from . import utils
from .shape import Shape
from .logger import logger
from .label_converter import LabelConverter

Expand Down Expand Up @@ -48,9 +49,10 @@ def load_image_file(filename, default=None):
# It may result in a slight performance overhead due to the additional processing and file I/O.
# A more efficient solution should be considered in the future.
from PIL import Image, ExifTags

with Image.open(filename) as img:
exif_data=None
if hasattr(img, '_getexif'):
exif_data = None
if hasattr(img, "_getexif"):
exif_data = img._getexif()
if exif_data is not None:
for tag, value in exif_data.items():
Expand Down Expand Up @@ -80,17 +82,6 @@ def load(self, filename):
"imageHeight",
"imageWidth",
]
shape_keys = [
"label",
"score",
"points",
"group_id",
"difficult",
"shape_type",
"flags",
"description",
"attributes",
]
try:
with io_open(filename, "r") as f:
data = json.load(f)
Expand All @@ -110,9 +101,9 @@ def load(self, filename):
"UserWarning: Diagonal vertex mode is deprecated in X-AnyLabeling release v2.2.0 or later.\n"
"Please update your code to accommodate the new four-point mode."
)
data["shapes"][i][
"points"
] = utils.rectangle_from_diagonal(shape_points)
data["shapes"][i]["points"] = (
utils.rectangle_from_diagonal(shape_points)
)

data["imagePath"] = osp.basename(data["imagePath"])
if data["imageData"] is not None:
Expand All @@ -133,26 +124,7 @@ def load(self, filename):
data.get("imageHeight"),
data.get("imageWidth"),
)
shapes = [
{
"label": s["label"],
"score": s.get("score", None),
"points": s["points"],
"shape_type": s.get("shape_type", "polygon"),
"flags": s.get("flags", {}),
"group_id": s.get("group_id"),
"description": s.get("description"),
"difficult": s.get("difficult", False),
"attributes": s.get("attributes", {}),
"other_data": {
k: v for k, v in s.items() if k not in shape_keys
},
}
for s in data["shapes"]
]
for i, s in enumerate(data["shapes"]):
if s.get("shape_type", "polygon") == "rotation":
shapes[i]["direction"] = s.get("direction", 0)
shapes = [Shape().load_from_dict(s) for s in data["shapes"]]
except Exception as e: # noqa
raise LabelFileError(e) from e

Expand Down
Loading

0 comments on commit 24d14f2

Please sign in to comment.