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 Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

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