How to Extract Text from Image & PDF Files
The Nanonets free online OCR (optical character recognition) service allows you to extract text from images and documents accurately, at scale, and in multiple languages. Most OCR APIs today just do a blind data dump of the unstructured data in images and documents; and a lot of time goes into cleaning up the extracted text and data. Nanonets is the only text recognition OCR that presents extracted text & data in neatly structured & organized formats that are entirely customizable. Captured data can be presented as tables, line items, or any other format.
Here are three ways in which you can use Nanonets OCR to detect and extract text from images, PDFs and other document types.
Table of Contents
- How to extract text from images and PDFs using Nanonets pre-trained OCR models
- How to extract text from images and PDFs by building a custom Nanonets OCR model
- How to train your own models for an OCR software or OCR application using NanoNets API
- 7 Reasons why Nanonets OCR API is better than other OCR APIs
How to extract text from images and PDFs using Nanonets pre-trained OCR models
Nanonets has pre-trained OCR models for the specific document types listed below. Each pre-trained OCR model is trained to accurately relate text in the image/document type to an appropriate field like name, address, date, expiry etc.
- Driver’s license (US)
- Menu cards
- License plates
- Meter readings
- Shipping containers
Step 1: Select an appropriate OCR model
Login to Nanonets and select an OCR model that is appropriate to the file or document from which you want to digitally extract text and data. If none of the pre-trained OCR models suit your requirements, you can skip ahead to find out how to create your own OCR model.
Step 2: Add files
Add the files/images/documents from which you want to extract text. You can add as many files as you like.
Step 3: Test
Allow a few seconds for the model to run and extract the text/data from the image/document.
Step 4: Verify
Quickly verify the data extracted from each file, by checking the table view on the right. You can easily double-check whether the text has been correctly recognised and matched with an appropriate field or tag.
You can even choose to edit/correct the field values and labels at this stage. Nanonets is not bound by the template of the document.
The extracted data can be displayed in a “List View” or “JSON” format.
You can tick the checkbox beside each value or field you verify or click “Verify Data” to proceed instantly.
Step 5: Export
Once all the files have been verified. You can export the neatly organized data as an xml, xlsx or csv file.
Notice how the extracted data has been organized and presented in a format that is neat, convenient and comprehensible.
How to extract text from images and PDFs 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 document 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
Login to Nanonets and click on “Create your own OCR model”.
Step 2: Upload training files/images
Upload sample files that will be used to train the OCR models. The accuracy of the OCR model you build will largely depend on the quality and quantity of the files/images uploaded at this stage
Step 3: Annotate text on the files/images
Now annotate each piece of text or data with an appropriate field or label. This crucial step will teach your OCR model to extract the appropriate text from images and associate it with custom fields that are relevant to your needs.
You can also add a new label to annotate the text or data. Remember, Nanonets is not bound by the template of the document.
Step 4: Train the custom OCR model
Once annotation is completed for all the training files/images, click on “Train Model”. Training usually takes between 20 mins-2 hours depending on the number of files and queued models for training. You can upgrade to a paid plan to get faster results at this stage (typically under 20 minutes).
Nanonets leverages deep learning to build various OCR models and tests them against each other for accuracy. Nanonets then picks out the best OCR model (based on your inputs and accuracy levels). The “Model Metrics” tab shows the various measurements and comparative analyses that allowed Nanonets to pick the best OCR model among all that were built. You can retrain the model (by providing a wider range of training images and better annotation) to achieve higher levels of accuracy.
Or, if you’re satisfied with the accuracy, click on “Test” to test & verify whether this custom OCR model performs as expected on a sample of images or files from which text/data needs to be extracted.
Step 5: Test & verify data
Add a couple of sample images to test & verify the custom OCR model.
If the text has been recognised, extracted and presented appropriately then export the file. As you can see below, the extracted data has been organized and presented in a neat format.
Congratulations, you have now built and trained your own online OCR tool!
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
Step 4: Create a New Model
Note: This generates a MODEL_ID that you need for the next step
Step 5: Add Model Id as Environment Variable
Step 6: Upload the Training Data
Collect a dataset of training images or documents from which you would like to recognize & extract text. Once you have dataset ready in the folder
images (image files), start uploading the dataset.
Step 7: Train Model
Once the Images have been uploaded, begin training the Model
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
7 Reasons why Nanonets OCR API is better than other OCR APIs
The benefits of using Nanonets over other OCR APIs go beyond just better accuracy with respect to extracting text from images. Here are 7 reasons why you should consider using the Nanonets OCR API for text recognition instead of other OCR APIs.
- Working with custom data - Most OCR APIs are quite rigid on the type of data they can work with. Training an OCR model for a use case requires a large degree of flexibility with respect to its requirements and specifications; an OCR for invoice processing will vastly differ from an OCR for passports! Nanonets isn’t bound by such rigid limitations. Nanonets uses your own data to train OCR models that are best suited to meet the particular needs of your business.
- Working with non-English or multiple languages - Since Nanonets focuses on training with custom data, it is uniquely placed to build a single OCR model that could extract text from documents in any language or multiple languages at the same time.
- Requires almost no post-processing - Text extracted using OCR models needs to be intelligently structured and presented in an intelligible format; otherwise considerable time and resources go into re-organizing the data into meaningful information. While most OCR APIs simply grab and dump data from images and documents, Nanonets extracts only the relevant data and automatically sorts them into intelligently structured fields making it easier to view and understand.
- Learns continuously - Businesses often face dynamically changing requirements and needs. To overcome potential roadblocks, Nanonets OCR API allows you to easily re-train your models with new data. This allows your OCR model to adapt to unforeseen changes.
- Handles common data constraints with ease - Nanonets OCR API leverages deep learning & object detection techniques to overcome common data constraints that greatly affect text recognition and extraction. Nanonets OCR can recognize and handle handwritten text, images of text in multiple languages at once, images with low resolution, images with new or cursive fonts and varying sizes, images with shadowy text, tilted text, random unstructured text, image noise, blurred images and more. Traditional OCR APIs are just not equipped to perform under such constraints; they require data at a very high level of fidelity which isn’t the norm in real life scenarios.
- Requires no in-house team of developers - No need to worry about hiring developers and acquiring talent to personalize Nanonets API for your business requirements. Nanonets was built for hassle-free integration. You can also easily integrate Nanonets with most CRM, ERP or RPA software.
- Customise, customise, customise - You can capture as many fields of text/data that you like with Nanonets OCR. You can even build custom validation rules that work for your specific text recognition and text extraction requirements. Nanonets is not bound by the template of your document at all. You can capture data in tables or line items or any other format!
And here are a couple of success stories in which businesses succesfully leveraged Nanonets to achieve their intended goals:
- Nanonets OCR enabled a Fortune 500 company in the US to build an automated invoice processing solution for 5+ languages with 95% accuracy, automating upto 80% of manual data entry, along with on-premises deployments.
- Nanonets API also equipped a Large Recruitment Agency in Europe to process 10 different document types - educational certificates, immigration forms, bank account statements, ID cards etc. across diverse templates to help grow business 2x in a year.
Does your business deal with text recognition in digital documents, images or PDFs? Have you wondered how to extract text from images accurately? Nanonets has many use cases that could optimize your business performance, save costs and boost growth. Find out how Nanonets' use cases can apply to your product.