(image)
| 10 | def resize_with_pad(image, height=IMAGE_SIZE, width=IMAGE_SIZE): |
| 11 | |
| 12 | def get_padding_size(image): |
| 13 | h, w, _ = image.shape |
| 14 | longest_edge = max(h, w) |
| 15 | top, bottom, left, right = (0, 0, 0, 0) |
| 16 | if h < longest_edge: |
| 17 | dh = longest_edge - h |
| 18 | top = dh // 2 |
| 19 | bottom = dh - top |
| 20 | elif w < longest_edge: |
| 21 | dw = longest_edge - w |
| 22 | left = dw // 2 |
| 23 | right = dw - left |
| 24 | else: |
| 25 | pass |
| 26 | return top, bottom, left, right |
| 27 | |
| 28 | top, bottom, left, right = get_padding_size(image) |
| 29 | BLACK = [0, 0, 0] |