How to Build a Monitoring Application With the Google Cloud Vision API

The setup for this application is fairly simple to demonstrate. It comprises the following:

  1. You can use any microcomputer like Raspberry Pi, Tessel or others with a camera module to monitor the area where the system is setup. In our case, we used a Tessel with the Camera module.
  2. The code running on the Tessel is a simple Node.js app that captures a photo, at a defined interval (30 seconds) and writes this image to the system.
  3. We write a basic Python application next to analyze the images one by one and if it contains certain labels that were detected as part of the LABEL_DETECTION feature then we highlight those.

While we demonstrate the pieces that you will need to accomplish the above step by step, it is easy to see how you could combine them into an overall application and also add some alerting logic of your own.

Tessel Microcontroller - Node.js Application to Capture the Image

var tessel = require('tessel');
var camera = require('camera-vc0706').use(tessel.port['A']);

// Wait for the camera module to say it's ready

camera.on('ready',  Function() {
   // Take the picture
   setInterval( function(){
      camera.takePicture(function(err, image) {
        if (err) {
           console.log('error taking image', err);
          } else {
             // Name the image
             var name = 'picture-' + + '.jpg';
             // Save the image
             console.log('Picture saving as', name, '...');
             process.sendfile(name, image);

camera.on('error', function(err) {

The Node program is straightforward and even if you do not have a Tessel, you can identify that the initial couple of lines was just to initialize the tessel Library and the camera library. The rest of the code is as follows:

  1. Once the Camera module is ready, we use the JavaScript SetInterval function to invoke a piece of code every 5 seconds (5000 milliseconds).
  2. This code, uses the camera module to take a picture and saves it with a unique filename.

Once we begin running the application, over time it will produce images, which you could then analyze using the Cloud Vision API. Of course, we could integrate the Cloud Vision API here directly but the Decoupling is done to help you understand different parts of the system and also to effectively demonstrate that your image capturing process could be completely separate.

Python App to Analyze the Image

The Camera image capture and writing those images to the system is not a part of the Google Cloud Vision Workflow. Now that we have the images and want to analyze each of them, let us look at what we need to do to invoke the API.

Here are the steps that are necessary to use the Google Cloud Vision API:

1. Create Google Cloud Platform Project

Head over to the Google Cloud Platform Developers Console and login with your account. Ensure that you have a Billing Account setup with Google Cloud Platform.

Go to the list of all projects for your account and click on the Create Project button to create a new project. This will bring up the form as shown below:

google cloud vision api create project

Enter a name for your project and select the Billing account that you want to apply to your project. Click on Create.

Be sure to read the next Machine Learning article: An Analysis of Brexit With the MonkeyLearn Machine Learning API