## ScriptReader

This handwriting OCR application can convert JPEG handwritten text images into RTF documents, while removing typos for you!

**ScriptReader** is a tool enabling you to convert scanned handwritten pages (in JPEG image format) into rich text format (RTF) documents, complete with formatting elements such as text alignment, paragraphs, underline, _italics_, **bold** and ~~strikethrough~~.

A neat functionality of **ScriptReader** is that the typos (square dot grid cells containing mistakes, which are filled in with ink) automatically get filtered out, and do not appear in the final RTF text. Also, the biodegradable fountain pen ink pairs well with the notebooks that you print with PrintANotebook!

My tests with over 30,000 characters of training data (about 50 half-letter pages of cursive handwriting) consistently gave me an **OCR accuracy above 99%!**

## 📝 Table of Contents

- [Dependencies / Limitations](/content/LPBeaulieu/Handwriting-OCR-ScriptReader#limitations/index.html)
- [Getting Started](/content/LPBeaulieu/Handwriting-OCR-ScriptReader#getting_started/index.html)
- [Usage](/content/LPBeaulieu/Handwriting-OCR-ScriptReader#usage/index.html)
- [Author](/content/LPBeaulieu/Handwriting-OCR-ScriptReader#author/index.html)
- [Acknowledgments](/content/LPBeaulieu/Handwriting-OCR-ScriptReader#acknowledgments/index.html)

## ⛓️ Dependencies / Limitations

This Python project relies on the Fastai deep learning library to generate a convolutional neural network deep learning model, which allows for handwriting optical character recognition (OCR). It also needs OpenCV to perform image segmentation.

A deep learning model trained with a specific handwriting is unlikely to generalize well to other handwritings. It is advisable to keep your dataset private, as it would in theory be possible to reverse engineer it to generate text with your handwriting.

The **ScriptReader** pages from PrintANotebook need to be used, and the individual letters need to be written within the vertical boundaries of a given dot grid square cell (comprised of four dots). The handwritten pages should be **scanned at a resolution of 300 dpi, with the US Letter page size setting**.

**Here is a list of the most common RTF commands:**

- **"\\b":** Bold opening tag **"\\b0":** Bold closing tag
- **"\\i":** Italics opening tag **"\\i0":** Italics closing tag
- **"\\ul":** Underline opening tag **"\\ul0":** Underline closing tag
- ...

## 🏁 Getting Started

The following instructions will allow you to run a copy of **ScriptReader** on a local computer.

1. Install **PyTorch**:
   ```
   pip3 install torch torchvision torchaudio
   ```
2. Install Fastai:
   ```
   py -m pip install fastai
   ```
3. Install OpenCV:
   ```
   py -m pip install opencv-python
   ```
4. Install alive-Progress:
   ```
   py -m pip install alive-progress
   ```
5. Install glob:
   ```
   py -m pip install glob2
   ```
6. Install TextBlob:
   ```
   py -m pip install textblob
   ```
7. Create folders:
   ```
   mkdir "OCR Raw Data"
   mkdir "Training&Validation Data"
   ```
8. You're now ready to use **ScriptReader**! 🎉

## 🎈 Usage

First off, you will need to print some **ScriptReader** notebook pages, which are special dot grid pages with line spacing in-between lines of text. For a basic template, simply pass in "scriptreader:" as an additional argument when running **PrintANotebook**.

Also, these pages have black squares in the top of the page, which help the code to automatically align the pages. You could write with any color of ink, as long as it is saturated enough to be picked up by your scanner.

To keep things as simple as possible in the default **basic RTF mode** of the "get_predictions.py" code.

## ✍️ Authors

- 👋 Hi, I’m Louis-Philippe!
- 👀 I’m interested in natural language processing (NLP) and anything to do with words!
- 📫 Contact: [LPBeaulieu@gmail.com](mailto:LPBeaulieu@gmail.com) 💻

## 🎉 Acknowledgments

- Hat tip to [@kylelobo](/content/kylelobo/index.html) for the GitHub README template!

## About

ScriptReader allows you to perform Optical Character Recognition (OCR) on your handwritten notes!
