Image Recognition using Google Vision API

September 20, 2018
Achin Verma
What is Image recognition?

 

Image recognition is the concept of machine learning which focuses on identifying the objects, places, peoples and several other variables in the image.

Basically, in image recognition, the first step is image classification. In image classification, the system extracts the important data/information and features from the images.

For example, in the below image if you want to extract cat from the background you will notice a significant variation in RGB pixel values. The task in Image Classification is to take an array of pixels that represents a single image and assign a label to it.

Image-Recognition-using-Google-Vision-API

  • General Approaches to Image Classification:
  1. Unsupervised
  2. Supervised

Unsupervised Classification – Unsupervised classification (commonly referred to as clustering) is the method of partitioning remote sensor image data in multispectral feature space and extracting land-cover information

Supervised Classification – Supervised classification is the technique used for the quantitative analysis of remote sensing image data.It can be divided into two type-

  • Training phase – in this phase the classification algorithm is provided to identify classes uniquely and respective no of pixels is assigned to a particular class in which the particular image belongs.
  • Classification phase – In this, the algorithm used the training data files to by looking each pixel in the trained classes and assign classes to each pixel.
  • Image Recognition Techniques

In mobile, web and software development there are a lot of techniques are present like-TensorFlow by Google, DeepFace by Facebook and On the other side, hosted APIs like Google Cloud Vision, Microsoft computer vision API. These API’s are paid.

Here we will discuss Google Cloud Vision API in android. In this, we will learn how we will use the mobile device camera to identify the images.

  • How does Google Cloud Vision Api work?

Google Cloud Vision API will identify images from pre-trained models on large images datasets of images and then it classifies the images into thousands of categories to detect the objects, places, people and faces in the images and then prints the results with the confidence value.

If you want to use the Google Cloud Vision API, Google has introduced the API for developers. Developers can use this API in C#, GO, JAVA, NODE.JS, PHP, PYTHON, RUBY. This API takes input an image, and the results back you the output in the form of BatchAnnotateImagesResponse.

How to use the Google Vision API?

  • Setting up the Google Vision API
  1.  To use the Google Vision API, you have to sign up for a Google Compute Engine Account. GCE is free to try but you will need a credit card to sign up.
  2. Then create a project in the developer console.
  3. Click on the credentials drop down menu and select OAuth Client ID: AND Select application type as Android. Enter your SHA1 fingerprint AND the package name of your app: It must be the same as the one declared in the build.gradle of your app. Then get yourself an API key from the left-hand menu.
  4. Enable the API on your project (go to this URL and click Enable the API):

Now you’re ready to go! Now we will see how Google”s API gives us output using a mobile”s camera.

In build.gradleadd below dependencies

Image-Recognition-using-Google-Vision-API-Blogs

We will use the Google API Client library Code because we are using the OAuth request, So first we need to obtain the auth token from Google.

Image-Recognition-using-Google-Vision-API

Image-Recognition-using-Google-Vision-API

Now we have got the parameters to call the Cloud Vision API and receive the results.

Image-Recognition-using-Google-Vision-API

Image-Recognition-using-Google-Vision-API

Image-Recognition-using-Google-Vision-API

Image-Recognition-using-Google-Vision-API

Latest posts by Achin Verma (see all)