@@ -55,6 +55,50 @@ def interpolator(start, end, progress):
5555
5656 converter .registered_interpolators [obj .feature_schema_id ] = interpolator
5757
58+ def polygon_converter_ (obj , converter , tensor_name , context , generate_labels ):
59+ ds = context ["ds" ]
60+ try :
61+ ds .create_tensor (tensor_name , ** polygon_tensor_create_kwargs_ ())
62+ except :
63+ pass
64+
65+ if generate_labels :
66+ print ("polygon converter does not support generating labels" )
67+
68+ converter .register_feature_id_for_kind ("tool" , "polygon" , obj , tensor_name )
69+
70+ def polygon_converter (row , obj ):
71+ if tensor_name not in converter .values_cache :
72+ converter .values_cache [tensor_name ] = dict ()
73+ if row not in converter .values_cache [tensor_name ]:
74+ converter .values_cache [tensor_name ][row ] = []
75+ polygon = obj ["polygon" ]
76+ if len (polygon ) != 0 and not isinstance (polygon [0 ], dict ):
77+ # if polygon is a list of points, convert it to a list of dicts
78+ polygon = [{"x" : float (p [0 ]), "y" : float (p [1 ])} for p in polygon ]
79+ converter .values_cache [tensor_name ][row ].append (
80+ np .array ([[float (p ["x" ]), float (p ["y" ])] for p in polygon ])
81+ )
82+
83+ converter .regsistered_actions [obj .feature_schema_id ] = polygon_converter
84+
85+ def interpolator (start , end , progress ):
86+ start_polygon = start ["polygon" ]
87+ end_polygon = end ["polygon" ]
88+ polygon = copy .deepcopy (start )
89+ polygon ["polygon" ] = [
90+ [
91+ start_polygon [i ]["x" ]
92+ + (end_polygon [i ]["x" ] - start_polygon [i ]["x" ]) * progress ,
93+ start_polygon [i ]["y" ]
94+ + (end_polygon [i ]["y" ] - start_polygon [i ]["y" ]) * progress ,
95+ ]
96+ for i in range (len (start_polygon ))
97+ ]
98+
99+ return polygon
100+
101+ converter .registered_interpolators [obj .feature_schema_id ] = interpolator
58102
59103def radio_converter_ (obj , converter , tensor_name , context , generate_labels ):
60104 ds = context ["ds" ]
@@ -199,9 +243,12 @@ def polygon_converter(row, obj):
199243 converter .values_cache [tensor_name ] = dict ()
200244 if row not in converter .values_cache [tensor_name ]:
201245 converter .values_cache [tensor_name ][row ] = []
202-
246+ line = obj ["line" ]
247+ if len (line ) != 0 and not isinstance (line [0 ], dict ):
248+ # if line is a list of points, convert it to a list of dicts
249+ line = [{"x" : int (l [0 ]), "y" : int (l [1 ])} for l in line ]
203250 converter .values_cache [tensor_name ][row ].append (
204- [[int (l ["x" ]), int (l ["y" ])] for l in obj [ " line" ] ]
251+ [[int (l ["x" ]), int (l ["y" ])] for l in line ]
205252 )
206253
207254 converter .regsistered_actions [obj .feature_schema_id ] = polygon_converter
0 commit comments