| 72 | |
| 73 | |
| 74 | class CenterSquareResize(MapDataComponent): |
| 75 | def __init__(self, ds, index=0): |
| 76 | """See section 5.3 |
| 77 | """ |
| 78 | def func(img): |
| 79 | try: |
| 80 | h, w, _ = img.shape |
| 81 | if h > w: |
| 82 | off = (h - w) // 2 |
| 83 | if off > 0: |
| 84 | img = img[off:-off, :, :] |
| 85 | if w > h: |
| 86 | off = (w - h) // 2 |
| 87 | if off > 0: |
| 88 | img = img[:, off:-off, :] |
| 89 | |
| 90 | img = cv2.resize(img, (256, 256)) |
| 91 | return img |
| 92 | except Exception: |
| 93 | return None |
| 94 | super(CenterSquareResize, self).__init__(ds, func, index=index) |
| 95 | |
| 96 | |
| 97 | # Testcode for encode/decode. |
no outgoing calls
no test coverage detected