Image to Text: How to Use OCR

Extracting text from images

Optical Character Recognition (OCR) can be used to convert shapes of text into text. It can be useful when you want to convert text from a physical source into notes, recover text from a screenshot or create a draft of a transcript from a handout. It is important to note that it is a draft. To use this tool, open it up and follow the simple steps.

Our test image was a synthetic JPG image of size 900 x 1200 pixels. The image contained a clear heading for our study notes and three short practice lines of text. We selected English and clicked the extract text button. The lines of text were extracted and we received a message informing us that 14 words had been extracted.

This guide has been created by the publisher and shows a simple success. However, this does not mean that all handwriting samples, textbook photos and complex tables will be recognised with the same accuracy. We have chosen a clear sample with printed text to demonstrate how to extract text from an image.

Preparation for OCR

Open up your source image. Ensure that the text you want to extract is readable. If you cannot read a character yourself then the OCR is unlikely to give you an accurate result. Try to use a better source.

If you are extracting text from a page, ensure that the page is upright and as flat as possible. Avoid heavy shadows over text. Try to capture the full amount of text you want. If there are lots of irrelevant background details, consider creating a new copy of the image with just the text. Keep the original image in case you need to go back to it if you have cropped the image too tightly and lost a heading, footnote or end of line.

Just because your image is large doesn’t mean the text is clear. If your image is very large and blurry, it will be hard to read. If your image is small, it may be clear if the screenshot was taken at an appropriate scale.

Screenshot showing the OCR screen. Contains an area to select image, language selection (English) and extract text button.

Select image and language

Click on the image selection area. Choose your JPG or other image. The area will update to show that your image has been selected (sample-1.jpg). This ensures that you are using the correct source. The extract text button will now be available.

Ensure that the language is set to English. If you have a document in a different language, select the correct language for your text. This is to ensure that the OCR recognises the text correctly. OCR is different to translation. They solve different issues.

Screenshot showing selected image (sample-1.jpg) and language (English).

Click the extract text button. The first time we ran this we received the text “Loading OCR engine (first run only)…”. The button will change to Cancel OCR whilst processing. We didn’t click the button again or select another image. Whilst processing we received a new output box and a message saying that we had completed.

The OCR tool uses an engine called Tesseract and runs locally. We saw that the text was processing and had completed. We did not test the network activity or use it offline. This is important to note when considering privacy issues. Our test was using harmless synthetic text.

Review extracted text

Once extracted we received an editable Recognised text box and a Copy text button. We received a message saying that we had completed and 14 words had been extracted. The text contained our heading, practice line, no personal information line and Chapter 1. There were some extra blank lines but the text matched the test image.

Screenshot showing completed OCR. Contains recognised text for our study notes, Copy text button and message saying 14 words extracted.

For this walkthrough we simply read through the text and noted it down. We did not test the Copy text button. The screenshot shows that the button was available. If you use it within your workflow, paste the text into somewhere that will keep it as plain text. This is a simple check to ensure that you have not accidentally copied the wrong text or an old value from your clipboard.

A good way to check the extracted text is to have the image next to you and read through it line by line. Check the heading, then each line of text and any small text. Don’t just read through and see if it makes sense. OCR can sometimes produce a word that sounds right but isn’t the correct word. Just because it sounds like it flows, doesn’t mean it is accurate.

Be careful with numbers and short text. A mistake with a number in a date, page number, quantity or exercise number can be a bigger issue than a spelling mistake in a long paragraph. Check that characters that look similar (capital I, lowercase l and number 1) are correct. If you are unsure, highlight them to review.

Formatting text

Once you have confirmed the text has been extracted correctly, you can format the text. The extra blank lines were easy to identify as they weren’t part of the text. The source only contained a few short lines. In a longer document the spacing may indicate paragraphs, headings or two columns. Don’t just make everything one paragraph.

The OCR won’t necessarily format the text the same as the source. The text may not be formatted as a table, two column text or captions in the correct place. If your source is a table, check that the values are correct for each label. If your source is a multi column page, check that the columns end and start in the correct place. If you have the correct words but they are in the wrong order it can still be misleading.

Grammar corrections and summarising can come later. If you use a rewriting tool before checking the text you can lose any clues that there has been a mistake. Once you have an accurate copy of the text, create a new version with edits or summary. Keep the source image in case you need to check anything.

What the test shows

We have shown that a clear printed sample can be recognised when we selected English. This gives us a practical guide to follow when extracting text from an image. It doesn’t show us how accurate it would be for a whole class of photos or handwriting. The font, lighting, angle and formatting can all affect how difficult it is.

If you are receiving a poor result, change a relevant factor. Check the language, improve the quality of your image or try a cleaner copy of your source. Just because you have lots of words in the result box doesn’t mean that the text from a photo is reliable. We want the text to match the image.

Consider what you are extracting and where you are using it. Just because you have a photo of a page doesn’t mean you can republish the whole thing. If you are using it for personal study or an authorised workflow, keep the source reference. Our sample was created specifically for this example and contained no private information.

Simple checks. Ensure that you have the correct image, language, completed extraction and checked line by line. Save your checked text with a descriptive name. Keep your image until any important uncertainties have been resolved. If you have a clear screenshot or photo of your printed notes try the tool. Remember that your first result is something to check.