How to do it...

The preceding algorithm in code is performed as follows (the code file is available as Handwritten_text_recognition.ipynb in GitHub):

  1. Download and import the dataset. This dataset will contain the images of handwritten text and their corresponding ground truth (transcription).
  2. Build a function that resizes pictures without distorting the aspect ratio and pad the rest of pictures so that all of them have the same shape:
def extract_img(img):     target = np.ones((32,128))*255     new_shape1 = 32/img.shape[0]     new_shape2 = 128/img.shape[1]     final_shape = min(new_shape1, new_shape2)     new_x = int(img.shape[0]*final_shape)     new_y = int(img.shape[1]*final_shape)     img2 = cv2.resize(img, (new_y,new_x ))     target[:new_x,:new_y] = img2[:,:,0] target[new_x:,new_y:]=255 ...

Get Neural Networks with Keras Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.