(self)
| 437 | # Go to next |
| 438 | |
| 439 | def overlay(self): |
| 440 | |
| 441 | self.temp = tempfile.mkdtemp() |
| 442 | |
| 443 | inference = self.previous_action_event.brain_inference |
| 444 | |
| 445 | # Assumes label_dict as label_file_id |
| 446 | |
| 447 | label_dict = inference.ai.ml.label_dict |
| 448 | |
| 449 | # Defaults to storing our db id : model sequential number ie 121 : 1 |
| 450 | # Use this to convert model output to get actual labels |
| 451 | inverted_label_file_dict = {v: k for k, v in label_dict.items()} |
| 452 | |
| 453 | # Class image() object |
| 454 | image = inference.file.image |
| 455 | |
| 456 | if not inference.boxes['boxes']: |
| 457 | return |
| 458 | |
| 459 | ## Now get the image and draw the overlay |
| 460 | |
| 461 | # Raw original image |
| 462 | data_tools = Data_tools().data_tools |
| 463 | |
| 464 | image_string = data_tools.download_bytes(image.url_signed_blob_path) |
| 465 | |
| 466 | image_np = imread(BytesIO(image_string)) |
| 467 | |
| 468 | # Convert to pill setup for drawing operations |
| 469 | pil_image = PIL_Image.fromarray(image_np) |
| 470 | |
| 471 | # Get overlay image |
| 472 | if self.action.overlay_kind == "image": |
| 473 | overlay_string = data_tools.download_bytes(image.url_signed_blob_path) |
| 474 | |
| 475 | # Convert to numpy array |
| 476 | overlay_blob_np = imread(BytesIO(overlay_string)) |
| 477 | |
| 478 | pil_overlay_image = PIL_Image.fromarray(overlay_blob_np) |
| 479 | |
| 480 | # TODO optional "normal" box drawing |
| 481 | |
| 482 | # Caution, this expects boxes to be in a list |
| 483 | # ie [ [0, 0, 0 ,0] ] even if only 1 box!!!! |
| 484 | |
| 485 | for i, box in enumerate(inference.boxes['boxes']): |
| 486 | |
| 487 | label = inference.classes['classes'][i] |
| 488 | score = inference.scores['scores'][i] |
| 489 | |
| 490 | label_file_id = inverted_label_file_dict[label] |
| 491 | |
| 492 | # Pass on files that aren't equal to chosen label |
| 493 | if int(label_file_id) != (self.action.overlay_label_file_id): |
| 494 | continue |
| 495 | |
| 496 | # Denormalize cordinates |
nothing calls this directly
no test coverage detected