How to Extract Text from Images
Originally published at https://nanonets.com on September 19, 2020, this article has been updated regularly.
Check out Nanonets’ free image to text OCR tool or read on to learn more about methods to extract text from images.
Extracting text from an image can be a cumbersome process. Most people just retype the text or data from the image; but this is both time-consuming and inefficient when you have a lot of images to deal with.
Image to text converters, often in-built as a sub-feature in image/document processing programs, offer a neat way to extract text from images. (Check out Nanonets’ free image to text and image to Excel tools)
Tools like Snagit & OneNote among others, leverage basic OCR (Optical Character Recognition) capabilities to extract text from images. While such tools do a good job, the extracted text/data is often presented in an unstructured manner that results in a lot of post processing effort.
An AI-driven OCR like Nanonets can extract text from images and present the extracted data in a neat, organized & structured manner. (What is OCR? — here’s a detailed explainer on OCR.)
Nanonets’ free online OCR allows you to extract text from images accurately, at scale, and in multiple languages.
Nanonets is the only text recognition OCR that presents extracted text in neatly structured & organized formats that are entirely customizable. Captured data can be presented as tables, line items, or any other format.
Find out why Nanonets is better than other OCR APIs.
Here are three ways in which you can use Nanonets OCR to detect and extract text from images, parse PDFs, extract text from PDFs, extract data from websites or extract data from PDFs and other document types:
- How to extract text from images using Nanonets pre-trained OCR models
- How to extract text from images by building a custom Nanonets OCR model
- How to train your own models for an OCR software or OCR application using Nanonets API
How to extract text from images using Nanonets pre-trained OCR models
Nanonets has pre-trained OCR models for the specific image types listed below. Each pre-trained OCR model is trained to accurately relate text in the image type to an appropriate field like name, address, date, expiry etc. and present the extracted text in a neat and organized manner.
- Invoices
- Receipts
- Driver’s license (US)
- Passports
- Menu cards
- Resumes
- License plates
- Meter readings
- Shipping containers
Step 1: Select an appropriate OCR model
Step 2: Add files
Step 3: Test
Step 4: Verify
Step 5: Export
How to extract text from images by building a custom Nanonets OCR model
Building a custom OCR model with Nanonets is easy. You can typically build, train and deploy a model for any image type, in any language, all in under 25 minutes (depending on the number of files used to train the model).
Watch the video below to follow the first 4 steps in this method:
Step 1: Create your own OCR model
Step 2: Upload training files/images
Step 3: Annotate text on the files/images
Step 4: Train the custom OCR model
Step 5: Test & verify data
How to train your own models for an OCR software or OCR application using Nanonets API
If you have an OCR software or application, here’s a detailed guide to train your own OCR models using the Nanonets API.
Step 1: Clone the Repo
git clone https://github.com/NanoNets/nanonets-ocr-sample-python cd nanonets-ocr-sample-python sudo pip install requests sudo pip install tqdm
Step 2: Get your free API Key
Get your free API Key from https://app.nanonets.com/#/keys
Step 3: Set the API key as an Environment Variable
export NANONETS_API_KEY=YOUR_API_KEY_GOES_HERE
Step 4: Create a New Model
python ./code/create-model.py
Note: This generates a MODEL_ID that you need for the next step
Step 5: Add Model Id as Environment Variable
export NANONETS_MODEL_ID=YOUR_MODEL_ID
Step 6: Upload the Training Data
Collect a dataset of training images from which you would like to recognize & extract text. Once you have dataset ready in the folder images
(image files), start uploading the dataset.
python ./code/upload-training.py
Step 7: Train Model
Once the Images have been uploaded, begin training the Model
python ./code/train-model.py
Step 8: Get Model State
The model takes ~30 minutes to train. You will get an email once the model is trained. In the meanwhile you can check the state of the model
watch -n 100 python ./code/model-state.py
Step 9: Make Prediction
Once the model is trained. You can make predictions using the model
python ./code/prediction.py PATH_TO_YOUR_IMAGE.jpg
Originally published at https://nanonets.com on September 19, 2020.
Here’s a slide summarizing this article.