| 30 | |
| 31 | |
| 32 | class Instance_tools(): |
| 33 | |
| 34 | def __init__(self): |
| 35 | self.temp = tempfile.mkdtemp() |
| 36 | |
| 37 | |
| 38 | def new_thumb_image_from_frame( |
| 39 | self, |
| 40 | session, |
| 41 | video, |
| 42 | instance): |
| 43 | |
| 44 | # new |
| 45 | if video.root_blob_path_to_frames: |
| 46 | root_path = video.root_blob_path_to_frames |
| 47 | # assumed to have trailing "/" |
| 48 | |
| 49 | blob_path = root_path + str(instance.frame_number) |
| 50 | |
| 51 | # migration |
| 52 | else: |
| 53 | if not instance.file.image: |
| 54 | return False |
| 55 | |
| 56 | blob_path = self.get_migration_path( |
| 57 | project = instance.file.project, |
| 58 | image = instance.file.image) |
| 59 | |
| 60 | image_np = data_tools.get_image(blob_path) |
| 61 | |
| 62 | cropped_image = self.crop_image(image_np, instance) |
| 63 | if cropped_image is False: |
| 64 | return False |
| 65 | |
| 66 | self.upload(session, instance, cropped_image) |
| 67 | |
| 68 | return True |
| 69 | |
| 70 | |
| 71 | def get_migration_path(self, project, image): |
| 72 | |
| 73 | return f"{settings.PROJECT_IMAGES_BASE_DIR + str(project.id)}/{str(image.id)}" |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | def crop_image(self, image, instance): |
| 79 | """ |
| 80 | |
| 81 | """ |
| 82 | x_min, y_min = instance.x_min, instance.y_min |
| 83 | x_max, y_max = instance.x_max, instance.y_max |
| 84 | print(x_min, y_min, x_max, y_max) |
| 85 | logger.debug(f"Min Coordinates: ({x_min},{y_min})") |
| 86 | logger.debug(f"Max Coordinates: ({x_max},{y_max})") |
| 87 | cropped_image = image[y_min : y_max, x_min : x_max] |
| 88 | |
| 89 | # Maintain aspect ratio |
no outgoing calls
no test coverage detected