Visualizing the characters in an optical character recognition database
We will now look at how to use neural networks to perform optical character recognition. This refers to the process of identifying handwritten characters in images. We will use the dataset available at http://ai.stanford.edu/~btaskar/ocr. The default file name after downloading is letter.data
. To start with, let's see how to interact with the data and visualize it.
How to do it…
- Create a new Python file, and import the following packages:
import os import sys import cv2 import numpy as np
- Define the input file name:
# Load input data input_file = 'letter.data'
- Define visualization parameters:
# Define visualization parameters scaling_factor = 10 start_index = 6 end_index = -1 h, w = 16, 8
- Keep looping through the file until the user presses the Esc key. Split the line into tab-separated characters:
# Loop until you encounter the Esc key with open(input_file, 'r') as f: for line in f.readlines...