How to do it...

  1. Import the following packages:
import os 
import sys 
import cv2 
import numpy as np 
  1. Load the input data:
in_file = 'words.data'  
  1. Define the visualization parameters:
scale_factor = 10 
s_index = 6 
e_index = -1 
h, w = 16, 8 
  1. Loop until you encounter the Esc key:
with open(in_file, 'r') as f: 
  for line in f.readlines(): 
    information = np.array([255*float(x) for x in line.split('t')[s_index:e_index]]) 
    image = np.reshape(information, (h,w)) 
    image_scaled = cv2.resize(image, None, fx=scale_factor, fy=scale_factor) 
    cv2.imshow('Image', image_scaled) 
    a = cv2.waitKey() 
    if a == 10: 
      break 
  1. Type python visualize_character.py to execute the code:
  1. The result obtained when visualize_character.py is executed is shown here:

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition 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.