MCPcopy Create free account
hub / github.com/PeizeSun/TransTrack / resize

Function resize

demo.py:134–157  ·  view source on GitHub ↗
(image, size=800, max_size=1333)

Source from the content-addressed store, hash-verified

132
133
134def resize(image, size=800, max_size=1333):
135 def get_size_with_aspect_ratio(image_size, size, max_size=None):
136 h, w = image_size
137 if max_size is not None:
138 min_original_size = float(min((w, h)))
139 max_original_size = float(max((w, h)))
140 if max_original_size / min_original_size * size > max_size:
141 size = int(round(max_size * min_original_size / max_original_size))
142
143 if (w <= h and w == size) or (h <= w and h == size):
144 return (h, w)
145
146 if w < h:
147 ow = size
148 oh = int(size * h / w)
149 else:
150 oh = size
151 ow = int(size * w / h)
152
153 return (oh, ow)
154
155 new_height, new_width = get_size_with_aspect_ratio(image.shape[:2], size, max_size)
156 resized_image = cv2.resize(image, (new_width, new_height))
157 return resized_image, new_height, new_width
158
159
160def main(args):

Callers 1

mainFunction · 0.70

Calls 1

Tested by

no test coverage detected