MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / __call__

Method __call__

openrec/preprocess/resize.py:285–304  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

283 self.max_ratio = image_shape[1] * 1.0 / image_shape[0]
284
285 def __call__(self, data):
286 img = data['image']
287 imgH, imgW = self.image_shape
288 h, w, imgC = img.shape
289 ratio = w / float(h)
290 max_wh_ratio = max(ratio, self.max_ratio)
291 imgW = int(imgH * max_wh_ratio)
292 if math.ceil(imgH * ratio) > imgW:
293 resized_w = imgW
294 else:
295 resized_w = int(math.ceil(imgH * ratio))
296 resized_image = cv2.resize(img, (resized_w, imgH))
297 resized_image = resized_image.astype('float32')
298 resized_image = resized_image.transpose((2, 0, 1)) / 255
299 resized_image -= 0.5
300 resized_image /= 0.5
301 padding_im = np.zeros((imgC, imgH, imgW), dtype=np.float32)
302 padding_im[:, :, 0:resized_w] = resized_image
303 data['image'] = padding_im
304 return data
305
306
307class NaSizeResize(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected