MCPcopy Index your code
hub / github.com/diffgram/diffgram / get_min_coordinates_instance

Method get_min_coordinates_instance

shared/annotation.py:1194–1246  ·  view source on GitHub ↗
(self, instance)

Source from the content-addressed store, hash-verified

1192 )
1193
1194 def get_min_coordinates_instance(self, instance):
1195 logger.debug(f"Getting min coordinates for {instance.id} - {instance.type}")
1196
1197 if instance.type in ['text_token', 'relation', 'global']:
1198 return 0, 0
1199
1200 if instance.type in ['box', 'polygon', 'point']:
1201 return instance.x_min, instance.y_min
1202
1203 elif instance.type == 'line':
1204 return min([p['x'] for p in instance.points['points']]), min([p['y'] for p in instance.points['points']])
1205 elif instance.type == 'cuboid':
1206 # Here we assume front face as xy max
1207 return min(
1208 instance.front_face['top_right']['x'],
1209 instance.front_face['bot_right']['x'],
1210 instance.front_face['top_left']['x'],
1211 instance.front_face['bot_right']['x'],
1212 instance.rear_face['top_right']['x'],
1213 instance.rear_face['bot_right']['x'],
1214 instance.rear_face['top_left']['x'],
1215 instance.rear_face['bot_right']['x'],
1216 ), min(
1217 instance.front_face['top_right']['y'],
1218 instance.front_face['bot_right']['y'],
1219 instance.front_face['top_left']['y'],
1220 instance.front_face['bot_right']['y'],
1221
1222 instance.rear_face['top_right']['y'],
1223 instance.rear_face['bot_right']['y'],
1224 instance.rear_face['top_left']['y'],
1225 instance.rear_face['bot_right']['y'],
1226 )
1227 elif instance.type == 'ellipse':
1228 return instance.center_x - instance.width, instance.center_y - instance.height
1229 elif instance.type == 'curve':
1230 # Here assumption is that one point is gonna be max and the other min
1231 return min(instance.p2['x'], instance.p1['x']), min(instance.p2['y'], instance.p1['y'])
1232 elif instance.type == 'tag':
1233 # Here assumption is that tag is not really a "spacial" thing so no idea for min/max applies here.
1234 return 0, 0
1235 elif instance.type == 'keypoints':
1236 # Here assumption is that tag is not really a "spacial" thing so no idea for min/max applies here.
1237 if not instance.nodes['nodes'][0]['x'] or not instance.nodes['nodes'][0]['y']:
1238 return 0, 0
1239 return min([p['x'] for p in instance.nodes['nodes']]), min([p['y'] for p in instance.nodes['nodes']])
1240 elif instance.type == 'cuboid_3d':
1241 return instance.center_3d['x'] - (instance.dimensions_3d['width'] / 2), \
1242 instance.center_3d['y'] - (instance.dimensions_3d['height'] / 2), \
1243 instance.center_3d['z'] - (instance.dimensions_3d['depth'] / 2)
1244 else:
1245 logger.error(f"Invalid instance type for image crop: {instance.type}")
1246 return None
1247
1248 def get_max_coordinates_instance(self, instance):
1249 logger.debug(f"Getting max coordinates for {instance.id} - {instance.type}")

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected