Integrating Google Cloud Vision API with Ruby for Image Object Detection
The primary goal of Google Cloud vision is for powerful image analysis.
Google Cloud Vision offers both pretrained models via an API and the ability to build custom models using AutoML Vision to provide flexibility depending on your use case.
Here are a few use cases where Google Cloud Vision is the best fit for you:
- Insight from your images – If you are building an application where you want to identify objects from the image
- Extract text – If you are playing with OCR and planning to extract text from the images
- Power of the web – If you want to use the power of the google image search and utilize the best-updated images
- Content moderation – To enable the “SafeSearch” on your site by detecting different types of content like adult content, violent or inappropriate content.
Google Cloud vision provides the API which you can use to utilize there all services. Let’s integrate the Google Cloud Vision API for our Ruby application. In this tutorial, we are going to prepare a script which helps us to identify the objects from the image.
Once you create a project. Now we need API credential keys to make API calls.
Go to the service account and click on “Create a key” from a stock column.
Select json and then click “Create”.
Now download that key.json file. And place it somewhere in your system.
$ export GOOGLE_APPLICATION_CREDENTIALS="<some path to the keys>/key.json"
Once you export the keys, now you are ready to integrate Google Cloud Vision with your Ruby app.
Now, Let’s install google-cloud-vision gem.
$ gem install google-cloud
Here I have one sample passport image. Let’s try to identify the objects from it.
We are going to use
Google::Cloud::Vision::ImageAnnotator service class to identify a face, landmark, logo, label, and text detection.
Here I have written a simple script which detects the object using the above API.
The output object also returns the polygon vertices to mark those objects on the image.
There are many other APIs available to fulfill different use cases which I mentioned in the beginning. I have covered the integration of Vision API with a small use case here. I will share more used cases with different scripts so keep following these articles.
Also, explore more about how to extracting text from image using Google Cloud vision OCR with Ruby in my next article.
Have a happy coding!
At BoTree Technologies, we build enterprise applications with our RoR team of 25+ engineers.
Consulting is free – let us help you grow!
Choose Your Language
- Digital Marketing
- IT Consulting
- Project Management