Skip to content

Commit db03b45

Browse files
authored
Merge pull request #250 from fastlabel/feature/yolo-polygon
fix ポリゴンをYOLOで出力した時の座標情報が4点しか出ない
2 parents c45eb72 + 18f0ec3 commit db03b45

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fastlabel/converters.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,24 @@ def __get_yolo_annotation(data: dict) -> dict:
656656
dh = 1.0 / data["height"]
657657
if annotation_type == AnnotationType.segmentation.value:
658658
return __segmentation2yolo(value, classes, dw, dh, points)
659+
elif annotation_type == AnnotationType.polygon.value:
660+
return _polygon2yolo(value, classes, dw, dh, points)
659661
else:
660662
bbox = __to_bbox(annotation_type, points)
661663
return __bbox2yolo(value, classes, dw, dh, bbox)
662664

663665

666+
def _polygon2yolo(value: str, classes: list, dw: float, dh: float, points: list):
667+
category_index = str(classes.index(value))
668+
# polygon の points は [x1, y1, x2, y2, ...] の形式
669+
# 各座標を正規化して一つのリストにまとめる
670+
normalized_coords = [
671+
str(_truncate(points[i] * (dw if i % 2 == 0 else dh), 7))
672+
for i in range(len(points))
673+
]
674+
return [" ".join([category_index] + normalized_coords)]
675+
676+
664677
def __segmentation2yolo(value: str, classes: list, dw: float, dh: float, points: list):
665678
objs = []
666679
category_index = str(classes.index(value))

0 commit comments

Comments
 (0)