@@ -656,11 +656,24 @@ def __get_yolo_annotation(data: dict) -> dict:
656
656
dh = 1.0 / data ["height" ]
657
657
if annotation_type == AnnotationType .segmentation .value :
658
658
return __segmentation2yolo (value , classes , dw , dh , points )
659
+ elif annotation_type == AnnotationType .polygon .value :
660
+ return _polygon2yolo (value , classes , dw , dh , points )
659
661
else :
660
662
bbox = __to_bbox (annotation_type , points )
661
663
return __bbox2yolo (value , classes , dw , dh , bbox )
662
664
663
665
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
+
664
677
def __segmentation2yolo (value : str , classes : list , dw : float , dh : float , points : list ):
665
678
objs = []
666
679
category_index = str (classes .index (value ))
0 commit comments