@@ -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+
664677def __segmentation2yolo (value : str , classes : list , dw : float , dh : float , points : list ):
665678 objs = []
666679 category_index = str (classes .index (value ))
0 commit comments