Audience
The goal of this tutorial is to help you develop applications using Google Cloud Vision API Document Text Detection. It assumes you are familiar with basic programming constructs and techniques, but even if you are a beginning programmer, you should be able to follow along and run this tutorial without difficulty, then use the Cloud Vision API reference documentation to create basic applications.
Prerequisites
- Set up a Cloud Vision API project in the Google Cloud console.
Set up your environment for using Application Default Credentials.
Python
- Install Python.
- Install pip.
- Install the Google Cloud Client Library and the Python Imaging Library.
Annotating an image using Document Text OCR
This tutorial walks you through a basic Vision API application that makes a
DOCUMENT_TEXT_DETECTION request, then processes the fullTextAnnotation
response.
A fullTextAnnotation is a structured hierarchical response for the UTF-8 text
extracted from the image, organized as
Pages→Blocks→Paragraphs→Words→Symbols:
Pageis a collection of blocks, plus meta-information about the page: sizes, resolutions (X resolution and Y resolution may differ).Blockrepresents one "logical" element of the page—for example, an area covered by text, or a picture or separator between columns. The text and table blocks contain the main information needed to extract the text.Paragraphis a structural unit of text representing an ordered sequence of words. By default, words are considered to be separated by word breaks.Wordis the smallest unit of text. It is represented as an array of Symbols.Symbolrepresents a character or a punctuation mark.
The fullTextAnnotation also can provide URLs to Web images that partially or
fully match the image in the request.
Complete code listing
As you read the code, we recommend that you follow along by referring to the Cloud Vision API Python reference.