tejitak / node-cloud-vision-api

Node client for Google Cloud Vision API
112 stars 14 forks source link

Node Cloud Vision API

node-cloud-vision-api is a node client wrapper for Cloud Vision API.

Cloud Vision API Docs https://cloud.google.com/vision/docs/

Note that currently only limited preview for alpha-test users.

Supported features

Feature Type Description
FACE_DETECTION Run face detection
LANDMARK_DETECTION Run models to execute landmark detection
LOGO_DETECTION Run models to execute product logo detection
LABEL_DETECTION Run models to execute Image Content Analysis
TEXT_DETECTION Run models to execute OCR on an image
SAFE_SEARCH_DETECTION Run models to compute image safe search properties

Setup

Preparation

Install

npm install node-cloud-vision-api --save

Auth

API requests on node-cloud-vision-api is internally managed by google-api-nodejs-client

You can setup auth data with the following samples

Sample

'use strict'
const vision = require('node-cloud-vision-api')

// init with auth
vision.init({auth: 'YOUR_API_KEY'})

// construct parameters
const req = new vision.Request({
  image: new vision.Image('/Users/tejitak/temp/test1.jpg'),
  features: [
    new vision.Feature('FACE_DETECTION', 4),
    new vision.Feature('LABEL_DETECTION', 10),
  ]
})

// send single request
vision.annotate(req).then((res) => {
  // handling response
  console.log(JSON.stringify(res.responses))
}, (e) => {
  console.log('Error: ', e)
})

See more in test_annotate.js

Remote image file sample

Image files on web can be specified with 'url' paramters in Image object

const req = new vision.Request({
  image: new vision.Image({
    url: 'https://scontent-nrt1-1.cdninstagram.com/hphotos-xap1/t51.2885-15/e35/12353236_1220803437936662_68557852_n.jpg'
  }),
  features: [
    new vision.Feature('FACE_DETECTION', 1),
    new vision.Feature('LABEL_DETECTION', 10),
  ]
})

See more in test_annotate_remote.js

Multiple Requests per API call

// construct parameters
// 1st image of request is load from local
const req1 = new vision.Request({
  image: new vision.Image({
    path: '/Users/tejitak/temp/test1.jpg'
  }),
  features: [
    new vision.Feature('FACE_DETECTION', 4),
    new vision.Feature('LABEL_DETECTION', 10),
  ]
})

// 2nd image of request is load from Web
const req2 = new vision.Request({
  image: new vision.Image({
    url: 'https://scontent-nrt1-1.cdninstagram.com/hphotos-xap1/t51.2885-15/e35/12353236_1220803437936662_68557852_n.jpg'
  }),
  features: [
    new vision.Feature('FACE_DETECTION', 1),
    new vision.Feature('LABEL_DETECTION', 10),
  ]
})

// send multi requests by one API call
vision.annotate([req1, req2]).then((res) => {
  // handling response for each request
  console.log(JSON.stringify(res.responses))
}, (e) => {
  console.log('Error: ', e)
})

See more in test_annotate_remote.js

Supported Node Version

Recommended node version is above v4.0.0 because this module is implemented with ES6.

How to create a PR

Fork the repository and create a PR to 'develop' branch.