Extract Text From Image using Google Cloud Vision API

on

|

views

and

comments

Dear Readers,

Welcome again! 🙂

In previous post, we learned about how to authenticate with Google Cloud API. If you have not read, you can read the full blog Here.

In this post, we are going to learn how to use Google Cloud API to Extract the Text ( both Handwriting & Computer Writing ) and how to Detect Multiple Objects in Same picture.

Google Cloud Image Extraction API – Here is the link for the official link of Google Cloud API.

Request Format – Google API Accepts the JSON body as input.

Below is the typical request that api accept to read the computer text.

{
  "requests": [
    {
      "image": {
        "content": "base64-encoded-image"
,
        "source": {
          "imageUri" : "cloud-storage-image-uri"
,
          "gcsImageUri" : "public hosted image url"
        }
      },
      "features": [
        {
          "type"  : "TEXT_DETECTION"
,
          "model" : "builtin/stable",
          "maxResults": 10
        }
      ]
    }
  ]
}

Below is the typical body to detect handwriting text. If you wanted to read the text which is written by hand then use type as “DOCUMENT_TEXT_DETECTION” the only change is the type of task which should be “DOCUMENT_TEXT_DETECTION”

Create an Apex Class Name it “GoogleCloudVisionAPI”

Methods in the class

Method Name Description
   
detectTextFromImage This method is used to detect the text from image and text might be computer written or hand written. This method also inserts text into a custom object.
detectObjectFromImage This method is used to identify the objects from the image and creates the data into a custom object.
detectLogoFromImage The method used to detect the logo from the image.
detectSafeFromImage The method used to check if the image is safe for children, adults, the image is racist or not.
doCallGcCloudAPI This is the main and reusable method that is used to call the google cloud API with the help of another method.
sendRequest This method is used to send the request to Google Cloud API and returns the response.
prepareBody This method is used to prepare the body for each request.

 

Click Here for complete code.

Below is the code for the class.

Note: – Please use the above GitHub Repo code to get the complete code and related classes which are used in parent class “GoogleCloudVisionAPI

Attached is the demo video

Thanks for reading 🙂

#Trailblazer #Sharing #GivingBack #Integration

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to start your AI Journey?

Table of Contents Introduction Are you tired of the same old world? Do you dream of painting landscapes with your code, composing symphonies with data, or...

The Secret Weapon: Prompt Engineering: 🪄

Table of Contents Introduction Crafting the perfect prompt is like whispering secret instructions to your AI muse. But there's no one-size-fits-all approach! Exploring different types of...

How to Singup for your own Production org?

Let's see how we can have our salesforce enterprise Salesforce Org for a 30-day Trial and use it as a Production environment. With the...

Recent articles

More like this

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential