def _pre_process_image(img_in, _parse_method): im = cv2.imread(img_in, cv2.IMREAD_GRAYSCALE) if np.size(im) == 1: # skip if the image data is corrupt. return None # reduce the size of form images so that it can fit in memory. if _parse_method in ["form", "form_bb"]: im, _ = resize_image(im, MAX_IMAGE_SIZE_FORM) if _parse_method == "line": im, _ = resize_image(im, MAX_IMAGE_SIZE_LINE) if _parse_method == "word": im, _ = resize_image(im, MAX_IMAGE_SIZE_WORD) img_arr = np.asarray(im) return img_arr
def handwriting_recognition_transform(image): image, _ = resize_image(image, line_image_size) image = mx.nd.array(image) / 255. image = (image - 0.942532484060557) / 0.15926149044640417 image = image.as_in_context(ctx) image = image.expand_dims(0).expand_dims(0) return image
def __getitem__(self, idx): filename, text = self.data[idx] image = cv2.imread(filename, 0) return resize_image(np.expand_dims(image, axis=2), (60, 200))[0], text