(self, instance)
| 1246 | return None |
| 1247 | |
| 1248 | def get_max_coordinates_instance(self, instance): |
| 1249 | logger.debug(f"Getting max coordinates for {instance.id} - {instance.type}") |
| 1250 | |
| 1251 | if instance.type in ['text_token', 'relation', 'global']: |
| 1252 | return 0, 0 |
| 1253 | |
| 1254 | if instance.type in ['box', 'polygon', 'point']: |
| 1255 | return instance.x_max, instance.y_max |
| 1256 | |
| 1257 | elif instance.type == 'line': |
| 1258 | return max([p['x'] for p in instance.points['points']]), max([p['y'] for p in instance.points['points']]) |
| 1259 | elif instance.type == 'cuboid': |
| 1260 | # Here we assume front face as xy max |
| 1261 | return max( |
| 1262 | instance.front_face['top_right']['x'], |
| 1263 | instance.front_face['bot_right']['x'], |
| 1264 | instance.front_face['top_left']['x'], |
| 1265 | instance.front_face['bot_right']['x'], |
| 1266 | instance.rear_face['top_right']['x'], |
| 1267 | instance.rear_face['bot_right']['x'], |
| 1268 | instance.rear_face['top_left']['x'], |
| 1269 | instance.rear_face['bot_right']['x'], |
| 1270 | ), max( |
| 1271 | instance.front_face['top_right']['y'], |
| 1272 | instance.front_face['bot_right']['y'], |
| 1273 | instance.front_face['top_left']['y'], |
| 1274 | instance.front_face['bot_right']['y'], |
| 1275 | |
| 1276 | instance.rear_face['top_right']['y'], |
| 1277 | instance.rear_face['bot_right']['y'], |
| 1278 | instance.rear_face['top_left']['y'], |
| 1279 | instance.rear_face['bot_right']['y'], |
| 1280 | ) |
| 1281 | elif instance.type == 'ellipse': |
| 1282 | return instance.center_x + instance.width, instance.center_y + instance.height |
| 1283 | elif instance.type == 'curve': |
| 1284 | # Here assumption is that one point is gonna be max and the other min |
| 1285 | return max(instance.p2['x'], instance.p1['x']), max(instance.p2['y'], instance.p1['y']) |
| 1286 | elif instance.type == 'tag': |
| 1287 | # Here assumption is that tag is not really a "spacial" thing so no idea for min/max applies here. |
| 1288 | return 0, 0 |
| 1289 | elif instance.type == 'keypoints': |
| 1290 | if not instance.nodes['nodes'][0]['x'] or not instance.nodes['nodes'][0]['y']: |
| 1291 | return 0, 0 |
| 1292 | return max([p['x'] for p in instance.nodes['nodes']]), max([p['y'] for p in instance.nodes['nodes']]) |
| 1293 | elif instance.type == 'cuboid_3d': |
| 1294 | return instance.center_3d['x'] + (instance.dimensions_3d['width'] / 2), \ |
| 1295 | instance.center_3d['y'] + (instance.dimensions_3d['height'] / 2), \ |
| 1296 | instance.center_3d['z'] + (instance.dimensions_3d['depth'] / 2) |
| 1297 | else: |
| 1298 | logger.error(f"Invalid instance type for image crop: {instance.type}") |
| 1299 | return None |
| 1300 | |
| 1301 | def update_instance(self, |
| 1302 | type: str, |
no outgoing calls
no test coverage detected