Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Computer Vision API - OCR to Text on PDF files

I'm attempting to leverage the Computer Vision API to OCR a PDF file that is a scanned document but is treated as an image PDF.

I've tested it and it tells me that the PDF is "InvalidImageFormat", "Input data is not a valid image". When I test it on a PNG, it works perfectly.

Is there anyway to use the API against a PDF image or is there an Azure API that I could use in conjunction to go PDF > PNG > Text?

like image 408
gschwendt Avatar asked Sep 28 '18 15:09

gschwendt


4 Answers

Edit

Since answering additional services have become available, although I have not personally tried some of them, they may suit this purpose.

https://docs.microsoft.com/en-us/azure/search/cognitive-search-concept-intro

And at some point in the future when It goes GA. https://aws.amazon.com/textract/

Original Answer

Unfortunately Azure has no PDF integration for it's Computer Vision API. To make use of Azure Computer Vision you would need to change the pdf to an image (JPG, PNG, BMP, GIF) yourself.

Google do now offer pdf integration and I have been seeing some really good results from it from my testing so far.

This is done through the asyncBatchAnnotateFiles Method of the vision Client (I have been using the NodeJS Variant of the API)

It can handle files up to 2000 pages, Results are divided up into 20 page segments and output to Google Cloud Storage.

https://cloud.google.com/vision/docs/pdf

like image 167
Kevin Duffy Avatar answered Sep 17 '22 12:09

Kevin Duffy


The latest OCR service offered recently by Microsoft Azure is called Recognize Text, which significantly outperforms the previous OCR engine. Recognize Text can now be used with Read, which reads and digitizes PDF documents up to 200 pages.

like image 41
TrnKh Avatar answered Sep 16 '22 12:09

TrnKh


There is a new cognitive service API called Azure Form Recognizer (currently in preview - November 2019) available, that should do the job:

https://azure.microsoft.com/en-gb/services/cognitive-services/form-recognizer/

It can process the file formats you wanted:

Format must be JPG, PNG, or PDF (text or scanned). Text-embedded PDFs are best because there's no possibility of error in character extraction and location.

https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/overview

Here is the link the official Form Recognizer API documentation:

https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api/operations/AnalyzeWithCustomModel

Note:

  • Form Recognizer is currently available in English, with additional language availability growing (4.12.2019)
  • Form Recognizer is available in the following Azure regions (4.12.2019): Canada Central, North Europe, West Europe, UK South, Central US, East US, East US 2, South Central US, West US https://azure.microsoft.com/en-in/global-infrastructure/services/?products=cognitive-services
like image 22
lux7 Avatar answered Sep 16 '22 12:09

lux7


Sorry you have to break the PDF pages into images (JPG and PNGs). Then send the images over to Computer Vision. It is also a good idea to break it down so that you don't have to OCR all pages, only the ones that have importance.

like image 32
El Barako Avatar answered Sep 18 '22 12:09

El Barako