| 63 | |
| 64 | |
| 65 | def crop_and_resize(image, height, width): |
| 66 | image = np.array(image) |
| 67 | image_height, image_width, _ = image.shape |
| 68 | if image_height / image_width < height / width: |
| 69 | croped_width = int(image_height / height * width) |
| 70 | left = (image_width - croped_width) // 2 |
| 71 | image = image[:, left: left+croped_width] |
| 72 | image = Image.fromarray(image).resize((width, height)) |
| 73 | else: |
| 74 | croped_height = int(image_width / width * height) |
| 75 | left = (image_height - croped_height) // 2 |
| 76 | image = image[left: left+croped_height, :] |
| 77 | image = Image.fromarray(image).resize((width, height)) |
| 78 | return image |
| 79 | |
| 80 | |
| 81 | class VideoData: |