Google’s Cloud Vision image recognition software uses machine learning to recognise the content of images to determine things like objects, colors, facial expressions and notable landmarks. The tool is available via the Google Cloud Vision API to enable sophisticated image analysis in apps, robots and other software systems to identify, classify and group images according to predefined parameters.
In this tutorial, Ivan Kutil shows followers how he built a simple traffic analysis tool that looks at real-time records of city traffic from webcams to determine the amount of traffic at a given time. The author set up a Google Sheet as a database for a new Apps Script project, then activated the API in the Developer Console and completed authentication with OAuth 2.0.
A simple script fetches the webcam image from its public URL as a Blob, converting it into base64 and sending it to Cloud Vision API with a parameter for label_detection. A JSON response delivers a description of the image according to the labels with a confidence score of between 0 and 1 as the highest and lowest confidence respectively.
Kutil then set up an automatic Apps Script to run every 5 minutes and results are shown on a graph over time. As an example, the “road” label showing a high confidence score (nearing 1) means the system recognised road in the image with high confidence, meaning that there was little traffic obscuring the camera’s view of the road.
Inversely, when the graph shows high confidence results for the “traffic” label, the system is confidently recognising traffic in the images, meaning the roads are busy. While this tool isn’t perfect, it serves as a valuable example of what can be achieved with Cloud Vision API and a few lines of code.