Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the labelme sizes instead of recomputing them #9

Merged
merged 1 commit into from
Dec 28, 2022
Merged
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
6 changes: 4 additions & 2 deletions labelme2coco/labelme2coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import List

import numpy as np
from PIL import Image
from sahi.utils.coco import Coco, CocoAnnotation, CocoCategory, CocoImage
from sahi.utils.file import list_files_recursively, load_json, save_json
from tqdm import tqdm
Expand Down Expand Up @@ -41,7 +40,10 @@ def get_coco_from_labelme_folder(
data = load_json(json_path)
# get image size
image_path = str(Path(labelme_folder) / data["imagePath"])
width, height = Image.open(image_path).size
# use the image sizes provided by labelme (they already account for
# things such as EXIF orientation)
width = data["imageWidth"]
height = data["imageHeight"]
# init coco image
coco_image = CocoImage(file_name=data["imagePath"], height=height, width=width)
# iterate over annotations
Expand Down