Skip to content

OCR with Google's AI technology (Cloud Vision API): Image/URL/PDF to Text

Notifications You must be signed in to change notification settings

lokesh97jain/OCR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

OCR

OCR (Optical Character Recognition) with Google's AI technology (Cloud Vision API).

The Vision API can detect and extract text from images.

Install

  1. Download Python 3.6+ or follow this guide from Google Cloud.

  2. Clone or download this repository.

  3. Install the required dependencies by running the following command in your terminal:

    !pip install google-cloud-vision google-auth.

Usage

usage: OCR [-h] [--url] [--document] [--languages LANGUAGES] [--full] [--confidence CONFIDENCE] [--key KEY] path

positional arguments:
  path                  path to image

optional arguments:
  -h, --help            show this help message and exit
  --url                 specify the path for an external image located on the Web (http:// or https://) or in Google Cloud Storage (gs://)
  --document            optimized for dense images
  --languages LANGUAGES, --language LANGUAGES
                        specify language hints from https://cloud.google.com/vision/docs/languages (comma separated)
  --full, --verbose     show full description (paragraphs, per-word confidence, boundaries...)
  --confidence CONFIDENCE
                        display possible mistakes for symbols with low confidence. Default: 0.6
  --key KEY             explicitly define the path to your service account JSON credentials

Authentication

Follow these instructions to set up a project with the Cloud Vision API enabled:

  1. Select or create a Google Cloud Platform project. Project name suggestion: OCR

  2. Enable Cloud Vision API for your project.

  3. Create a service account and get your JSON credentials. Service account name suggestion: OCR

  4. Make sure that billing is enabled for your project.

    Pricing is based on Google Cloud Vision API quota: 1,000 requests/month free

To authenticate your project you need to reference the service account JSON credentials you just downloaded. You have different options to do it, choose what you prefer:

service_account.json file

The JSON you downloaded in step 3 place it inside this repository folder.

--key parameter

Another option is to explicitly specify the --key parameter on every script execution:

OCR image.jpg --key "/path/to/service_account.json"

Environment variable

You can also set the GOOGLE_APPLICATION_CREDENTIALS environmental variable:

bash

Add to your .bash_profile file:

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account.json"

fish

Add to your config.fish file:

set -gx GOOGLE_APPLICATION_CREDENTIALS "/path/to/service_account.json"

Example

TAJ

from File: TAJ.jpg

Result: output.txt

About

OCR with Google's AI technology (Cloud Vision API): Image/URL/PDF to Text

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published