Setting up Google Cloud Vision API with Node.js
A step-by-step guide on setting up authentication and how to use Google Cloud Vision API in Node.js to build a simple app.
What is Google Cloud Vision API ?
It allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content.
Basically, it lets you upload an image and extract loads of machine-learning based information. Try it out here — just drag and drop your own image.
Setup and Authentication
1. Create a new Google Cloud Platform project here.
2. Enable billing.
3. Enable Google Cloud Vision API here.
4. Set up authentication here.
5. Generate a google-services.json key file from your project’s console.
6. Select “Create new key” from drop-down menu.
7. Make sure you select JSON, then click create.
This generates the json file to be injected in the root of your project directory.
Now, let’s get coding!
- In your terminal, create a new project and install the dependencies.
- Insert your key json file into the root of your directory. You can shorten the file name if you wish.
- Setup @google-cloud/vision package in main.js we created earlier.
- Replace keyFilename with your own key json file path. For reference, mine is “./APIKey.json”.
- Next, we call the client with method called labelDetection setting the image we want to process and get data from.
Test it out!
- Select your favorite image
- Pass image path (“./cinqueTerre”) into labelDetection and run it
- Voilà! Congrats! Running the code gave us our expected results 🎉
Who is using Google Vision API?
Alright, classifying your pet photos and identifying landmarks is fun and all, but is anyone actually using Google Vision in production? Yes! Here are some real-life examples:
- Disney: label detection in a scavenger hunt game
- Realtor.com: Vision API’s OCR on “For Sale” signs
- Airbus: uses machine learning to automate the process of detecting and correcting satellite images that contain imperfections such as the presence of cloud formation
Conclusion
So far, we’ve only scratched the surface on @google-cloud/vision. I hope this helped guide you through the tedious setup and authentication phase. Now, you’re equipped to explore the fun parts of Google Vision!