microsoft-computer-vision

0.4.2 • Public • Published

microsoft-computer-vision

npm version GitHub issues GitHub stars GitHub forks HitCount Build Status NSP Status GitHub license Build status

NPM

What is this package?

This is a wrapper package for Microsoft Computer Vision APIs, it serves as regular Node SDK due to no official one was published by Microsoft.


Table of Contents

Installation

npm install microsoft-computer-vision --save

Feature

  • Promise based
  • Easy function calls
  • Option of using different location of API to minimize responding time
  • Use new end point of {location}.api.cognitive.microsoft.com/vision instead of api.projectoxford.ai/vision
  • Support all available regions from Microsoft.

Support-Regions

Pass one of the following region into request-origin from method option.

  • westus
  • westus2
  • eastus
  • eastus2
  • southcentralus
  • westcentralus
  • westeurope
  • southeastasia
  • canadacentral
  • uksouth
  • japaneast
  • australiaeast
  • brazilsouth
  • centralindia
  • eastasia
  • northeurope
  • westeurope

API

Analyze-Image


Description

This operation extracts a rich set of visual features based on the image content.

Two input methods are supported -- (1) Uploading an image binray or (2) specifying an image URL. Within your request, there is an optional parameter to allow you to choose which features to return. By default, image categories are returned in the response.


Options

{
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>", // Required one only
    "visual-features":"Categories,Tags,Description,Faces,ImageType,Color,Adult", // Can be at least one or more, separated by comma
    "details" : "Celebrities, Landmarks", // Optional, separated by comma
    "language" : "en" //or "cn", if not specified, "en" by default
    "content-type": "application/json",
    "url": "image_url"
          //or
    "content-type": "application/octet-stream",
    "body": "image_binary"
  }

Function call

analyzeImage({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "visual-features":"Tags, Faces, (...)",
  "content-type": "content type",
  "url": "image_url" //or "body": "image_binary"
}).then((result)=>{
 
  // the tags are now in the result
 
}).catch((err)=>{
  throw err
})

Example of passing image by URL

microsofComputerVision.analyzeImage({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "content-type": "application/json",
  "url": "https://goo.gl/Hpz7gi",
  "visual-features":"Tags, Faces"
}).then((result) => {
     console.log(result)     // { tags:
                              //  [ { name: 'tree', confidence: 0.9994124174118042 },
                              //    { name: 'outdoor', confidence: 0.9984000325202942 },
                              //    { name: 'sky', confidence: 0.9974111914634705 },
                              //    { name: 'grass', confidence: 0.9564579725265503 },
                              //    { name: 'building', confidence: 0.9447041153907776 },
                              //    { name: 'castle', confidence: 0.6080892086029053 } ],
                              // requestId: 'c9c33a0d-7100-4cea-b37a-b93d2b3aff10',
                              // metadata: { width: 883, height: 589, format: 'Jpeg' },
                              // faces: [] }
}).catch((err)=>{
    throw err
 })

Example of passing image by binary

// Suppose you want get tag and face for /tests/image/test.jpg
 
const microsofComputerVision = require("microsoft-computer-vision")
fs.readFile('./tests/image/test.jpg', function(err, data) {
    if (err)
        throw err
 
    microsofComputerVision.analyzeImage({
      "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
      "request-origin":"<Choose-one-from-Supported-Regions>",
      "content-type": "application/octet-stream",
      "body": data,
      "visual-features":"Tags, Faces"
    }).then((result) => {
        console.log(result)
                                 // { tags:
                                 //  [ { name: 'tree', confidence: 0.9994124174118042 },
                                 //    { name: 'outdoor', confidence: 0.9984000325202942 },
                                 //    { name: 'sky', confidence: 0.9974111914634705 },
                                 //    { name: 'grass', confidence: 0.9564579725265503 },
                                 //    { name: 'building', confidence: 0.9447041153907776 },
                                 //    { name: 'castle', confidence: 0.6080892086029053 } ],
                                 // requestId: 'c9c33a0d-7100-4cea-b37a-b93d2b3aff10',
                                 // metadata: { width: 883, height: 589, format: 'Jpeg' },
                                 // faces: [] }
    }).catch((err)=>{
      throw err
    })
})

Example of passing image by multipart/form-data

 
// here use multer as multipart/form-data handler
 
const microsofComputerVision = require("microsoft-computer-vision")
const myKey = "xxxxxxxxx"
const path = require('path')
const express = require('express')
const app = express()
const multer  = require('multer')
const storage = multer.memoryStorage()
const upload = multer({ storage: storage }).single('image')
 
app.post('/upload',  (req, res, next) => {
  upload(req, res, function (err) {
    if (err) {
      // An error occurred when uploading
      console.log(err)
      return
    }
 
    // Everything went fine
    microsofComputerVision.analyzeImage({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "multipart/form-data",
      "body": req.file,
      "visual-features":"Tags, Faces",
      "request-origin":"westus"
    }).then((result) => {
        // do stuff with result
    }).catch((err)=>{
      throw err
    })
  })
})

Tag-Image


Description

This operation generates a list of words, or tags, that are relevant to the content of the supplied image. The Computer Vision API can return tags based on objects, living beings, scenery or actions found in images. Unlike categories, tags are not organized according to a hierarchical classification system, but correspond to image content. Tags may contain hints to avoid ambiguity or provide context, for example the tag "cello" may be accompanied by the hint "musical instrument". All tags are in English.

Two input methods are supported -- (1) Uploading an image binary or (2) specifying an image URL.


Options

{
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>", // Required one only
    "content-type": "application/json",
    "url": "image_url"
          //or
    "content-type": "application/octet-stream",
    "body": "image_binary"
  }

Function call

tagImage({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "content-type": "content type",
  "url": "image_url" //or "body": "image_binary"
}).then((result)=>{
 
  // the tags are now in the result
 
}).catch((err)=>{
  throw err
})

Example of passing image by URL

const microsofComputerVision = require("microsoft-computer-vision")
microsofComputerVision.tagImage({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "content-type": "application/json",
  "url": "https://goo.gl/Hpz7gi"
}).then((result)=>{
  console.log(result)        // { tags:
                              //  [ { name: 'tree', confidence: 0.9994124174118042 },
                              //    { name: 'outdoor', confidence: 0.9984000325202942 },
                              //    { name: 'sky', confidence: 0.9974111914634705 },
                              //    { name: 'grass', confidence: 0.9564579725265503 },
                              //    { name: 'building', confidence: 0.9447041153907776 },
                              //    { name: 'castle', confidence: 0.6080892086029053 } ],
                              // requestId: 'eaafdbce-fa0f-4395-9aa3-f09a6d8e1a62',
                              // metadata: { width: 883, height: 589, format: 'Jpeg' } }
}).catch((err)=>{
  throw err
})

Example of passing image by binary

// Suppose you want get tag for /tests/image/test.jpg
 
const microsofComputerVision = require("microsoft-computer-vision")
 
fs.readFile('./tests/image/test.jpg', function(err, data) {
    microsofComputerVision.tagImage({
      "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
      "request-origin":"<Choose-one-from-Supported-Regions>",
      "content-type": "application/octet-stream",
      "body": data
    }).then((result) => {
 
        console.log(result)        // { tags:
                                    //  [ { name: 'tree', confidence: 0.9994124174118042 },
                                    //    { name: 'outdoor', confidence: 0.9984000325202942 },
                                    //    { name: 'sky', confidence: 0.9974111914634705 },
                                    //    { name: 'grass', confidence: 0.9564579725265503 },
                                    //    { name: 'building', confidence: 0.9447041153907776 },
                                    //    { name: 'castle', confidence: 0.6080892086029053 } ],
                                    // requestId: 'eaafdbce-fa0f-4395-9aa3-f09a6d8e1a62',
                                    // metadata: { width: 883, height: 589, format: 'Jpeg' } }
    }).catch((err)=>{
      throw err
    })
})

Example of passing image by multipart/form-data

 
// here use multer as multipart/form-data handler
 
const microsofComputerVision = require("microsoft-computer-vision")
const myKey = "xxxxxxxxx"
const path = require('path')
const express = require('express')
const app = express()
const multer  = require('multer')
const storage = multer.memoryStorage()
const upload = multer({ storage: storage }).single('image')
 
app.post('/upload',  (req, res, next) => {
  upload(req, res, function (err) {
    if (err) {
      // An error occurred when uploading
      console.log(err)
      return
    }
 
    // Everything went fine
    microsofComputerVision.tagImage({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "multipart/form-data",
      "body": req.file,
      "request-origin":"westus"
    }).then((result) => {
        // do stuff with result
    }).catch((err)=>{
      throw err
    })
  })
})

Describe-Image


Description

This operation generates a description of an image in human readable language with complete sentences. The description is based on a collection of content tags, which are also returned by the operation. More than one description can be generated for each image. Descriptions are ordered by their confidence score. All descriptions are in English.

Two input methods are supported -- (1) Uploading an image binary or (2) specifying an image URL.


Options

{
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>", // Required one only
    "max-candidates":"1", // if not specified, library use 10 by default
    "content-type": "application/json",
    "url": "image_url"
          //or
    "content-type": "application/octet-stream",
    "body": "image_binary"
  }

Function call

describeImage({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "max-candidates":"1",
  "content-type": "content type",
  "url": "image_url" //or "body": "image_binary"
}).then((result)=>{
 
  // the tags are now in the result
 
}).catch((err)=>{
  throw err
})

Example of passing image by URL

const microsofComputerVision = require("microsoft-computer-vision")
microsofComputerVision.describeImage({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "max-candidates":"1",
  "content-type": "application/json",
  "url": "https://goo.gl/Hpz7gi"
}).then((result)=>{
  console.log(result)      // {
                            // "description": {
                            //     "tags": [
                            //         "outdoor",
                            //         "grass",
                            //         "building",
                            //         "large",
                            //         "front",
                            //          ...
                            //     ],
                            //     "captions": [
                            //         {
                            //             "text": "a castle with a clock tower in front of a building",
                            //             "confidence": 0.5546771291117777
                            //         },
                            //         {
                            //             "text": "a castle with a clock tower",
                            //             "confidence": 0.5470764456423322
                            //         }
                            //     ]
                            // },
                            // "requestId": "b8ded71f-d515-41d4-9ac2-39372c41b3d8",
                            // "metadata": {
                            //     "width": 883,
                            //     "height": 589,
                            //     "format": "Jpeg"
                            // }
}).catch((err)=>{
  throw err
})

Example of passing image by binary

// Suppose you want get description for /tests/image/test.jpg
 
const microsofComputerVision = require("microsoft-computer-vision")
 
fs.readFile('./tests/image/test.jpg', function(err, data) {
    microsofComputerVision.describeImage({
      "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
      "request-origin":"<Choose-one-from-Supported-Regions>",
      "max-candidates":"1",
      "content-type": "application/octet-stream",
      "body": data
    }).then((result) => {
        console.log(result)      // {
                                  // "description": {
                                  //     "tags": [
                                  //         "outdoor",
                                  //         "grass",
                                  //         "building",
                                  //         "large",
                                  //         "front",
                                  //          ...
                                  //     ],
                                  //     "captions": [
                                  //         {
                                  //             "text": "a castle with a clock tower in front of a building",
                                  //             "confidence": 0.5546771291117777
                                  //         },
                                  //         {
                                  //             "text": "a castle with a clock tower",
                                  //             "confidence": 0.5470764456423322
                                  //         }
                                  //     ]
                                  // },
                                  // "requestId": "b8ded71f-d515-41d4-9ac2-39372c41b3d8",
                                  // "metadata": {
                                  //     "width": 883,
                                  //     "height": 589,
                                  //     "format": "Jpeg"
                                  // }
  }
    }).catch((err)=>{
      throw err
    })
})

Example of passing image by multipart/form-data

 
// here use multer as multipart/form-data handler
 
const microsofComputerVision = require("microsoft-computer-vision")
const myKey = "xxxxxxxxx"
const path = require('path')
const express = require('express')
const app = express()
const multer  = require('multer')
const storage = multer.memoryStorage()
const upload = multer({ storage: storage }).single('image')
 
app.post('/upload',  (req, res, next) => {
  upload(req, res, function (err) {
    if (err) {
      // An error occurred when uploading
      console.log(err)
      return
    }
 
    // Everything went fine
    microsofComputerVision.describeImage({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "multipart/form-data",
      "max-candidates":"1",
      "body": req.file,
      "request-origin":"westus"
    }).then((result) => {
        // do stuff with result
    }).catch((err)=>{
      throw err
    })
  })
})

Image-Thumbnail


Description

This operation generates a thumbnail image with the user-specified width and height. By default, the service analyzes the image, identifies the region of interest (ROI), and generates smart cropping coordinates based on the ROI. Smart cropping helps when you specify an aspect ratio that differs from that of the input image

A successful response contains the thumbnail image binary. If the request failed, the response contains an error code and a message to help determine what went wrong.


Options

{
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>", // Required one only
    "width": "100",
    "height": "100",
    "smart-cropping": true // optional
    "content-type": "application/json",
    "url": "image_url"
          //or
    "content-type": "application/octet-stream",
    "body": "image_binary"
  }

Function call

imageThumbnail({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "width": "100",
  "height": "100",
  "smart-cropping": true
  "content-type": "content type",
  "url": "image_url" //or "body": "image_binary"
}).then((result)=>{
 
  // the tags are now in the result
 
}).catch((err)=>{
  throw err
})

Example of passing image by URL

const microsofComputerVision = require("microsoft-computer-vision")
microsofComputerVision.imageThumbnail({
  "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
  "request-origin":"<Choose-one-from-Supported-Regions>",
  "width": "100",
  "height": "100",
  "smart-cropping": true
  "content-type": "application/json",
  "url": "https://goo.gl/Hpz7gi"
}).then((thumbnailBinary)=>{
    // Do something to the binary
    fs.writeFile('/thumbnail.jpg', thumbnailBinary, 'binary', function(err) {
        if (err)
            throw err
    })
}).catch((err)=>{
  throw err
})

Example of passing image by binary

// Suppose you want get a 100x100 thumbnail for /tests/image/test.jpg
 
const microsofComputerVision = require("microsoft-computer-vision")
 
fs.readFile('./tests/image/test.jpg', function(err, data) {
    microsofComputerVision.imageThumbnail({
      "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
      "request-origin":"<Choose-one-from-Supported-Regions>",
      "width": "100",
      "height": "100",
      "smart-cropping": true
      "content-type": "application/octet-stream",
      "body": data
    }).then((thumbnailBinary) => {
      // Do something to the binary
      fs.writeFile('/thumbnail.jpg', thumbnailBinary, 'binary', function(err) {
          if (err)
              throw err
      })
  }
    }).catch((err)=>{
      throw err
    })
})

Example of passing image by multipart/form-data

 
// here use multer as multipart/form-data handler
 
const microsofComputerVision = require("microsoft-computer-vision")
const myKey = "xxxxxxxxx"
const path = require('path')
const express = require('express')
const app = express()
const multer  = require('multer')
const storage = multer.memoryStorage()
const upload = multer({ storage: storage }).single('image')
 
app.post('/upload',  (req, res, next) => {
  upload(req, res, function (err) {
    if (err) {
      // An error occurred when uploading
      console.log(err)
      return
    }
 
    // Everything went fine
    microsofComputerVision.imageThumbnail({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "multipart/form-data",
      "width": "100",
      "height": "100",
      "smart-cropping": true,
      "body": req.file,
      "request-origin":"westus"
    }).then((result) => {
        // do stuff with result
    }).catch((err)=>{
      throw err
    })
  })
})

ORC-Image


Description

Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream.

Upon success, the OCR results will be returned.

Two input methods are supported -- (1) Uploading an image binary or (2) specifying an image URL.


Options

{
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>", // Required one only
    "content-type": "application/json",
    "url": "image_url",
    "language": "{language}", // Can be one of the following
                              // unk (AutoDetect)
                              // zh-Hans (ChineseSimplified)
                              // zh-Hant (ChineseTraditional)
                              // cs (Czech)
                              // da (Danish)
                              // nl (Dutch)
                              // en (English)
                              // fi (Finnish)
                              // fr (French)
                              // de (German)
                              // el (Greek)
                              // hu (Hungarian)
                              // it (Italian)
                              // Ja (Japanese)
                              // ko (Korean)
                              // nb (Norwegian)
                              // pl (Polish)
                              // pt (Portuguese,
                              // ru (Russian)
                              // es (Spanish)
                              // sv (Swedish)
                              // tr (Turkish)
    "detect-orientation": true // optional
  }

Function call

orcImage({
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>",
    "content-type": "application/json",
    "url": "image_url",
    "language": "{language}",
    "detect-orientation": true
}).then((result)=>{
    // ORC are now in the result
}).catch((err)=>{
  throw err
})

Example of passing image by URL

const microsofComputerVision = require("microsoft-computer-vision")
microsofComputerVision.orcImage({
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>",
    "content-type": "application/json",
    "url": "http://cdn.quotesgram.com/img/81/49/660235022-Random-Funny-Quotes-.jpg",
    "language": "en",
    "detect-orientation": true
}).then((result)=>{
 
  console.log(JSON.stringify(result))        // {
                              //     "language": "en",
                              //     "textAngle": 0,
                              //     "orientation": "Up",
                              //     "regions": [
                              //         {
                              //             "boundingBox": "7,55,605,387",
                              //             "lines": [
                              //                 {
                              //                     "boundingBox": "7,55,603,65",
                              //                     "words": [
                              //                         {
                              //                             "boundingBox": "7,59,291,61",
                              //                             "text": "HOME:"
                              //                         },
                              //                         {
                              //                             "boundingBox": "326,55,284,65",
                              //                             "text": "Where"
                              //                         }
                              //                     ]
                              //                 },
                              //                 ...
                              //             ]
                              //         }
                              //     ]
                              // }
}).catch((err)=>{
  throw err
})

Example of passing image by binary

// Suppose you want get ORC analysis for /tests/image/orcTest.jpg
 
const microsofComputerVision = require("microsoft-computer-vision")
 
fs.readFile('./tests/image/orcTest.jpg', function(err, data) {
    microsofComputerVision.orcImage({
      "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
      "request-origin":"<Choose-one-from-Supported-Regions>",
      "language": "en",
      "detect-orientation": true,
      "content-type": "application/octet-stream",
      "body": data
    }).then((result) => {
      console.log(JSON.stringify(result))        // {
                                  //     "language": "en",
                                  //     "textAngle": 0,
                                  //     "orientation": "Up",
                                  //     "regions": [
                                  //         {
                                  //             "boundingBox": "7,55,605,387",
                                  //             "lines": [
                                  //                 {
                                  //                     "boundingBox": "7,55,603,65",
                                  //                     "words": [
                                  //                         {
                                  //                             "boundingBox": "7,59,291,61",
                                  //                             "text": "HOME:"
                                  //                         },
                                  //                         {
                                  //                             "boundingBox": "326,55,284,65",
                                  //                             "text": "Where"
                                  //                         }
                                  //                     ]
                                  //                 },
                                  //                 ...
                                  //             ]
                                  //         }
                                  //     ]
                                  // }
  }
    }).catch((err)=>{
      throw err
    })
})

Example of passing image by multipart/form-data

 
// here use multer as multipart/form-data handler
 
const microsofComputerVision = require("microsoft-computer-vision")
const myKey = "xxxxxxxxx"
const path = require('path')
const express = require('express')
const app = express()
const multer  = require('multer')
const storage = multer.memoryStorage()
const upload = multer({ storage: storage }).single('image')
 
app.post('/upload',  (req, res, next) => {
  upload(req, res, function (err) {
    if (err) {
      // An error occurred when uploading
      console.log(err)
      return
    }
 
    // Everything went fine
    microsofComputerVision.orcImage({
      "Ocp-Apim-Subscription-Key": myKey, "content-type": "multipart/form-data", "language": "en",
      "detect-orientation": true,
      "body": req.file,
      "request-origin":"westus"
    }).then((result) => {
        // do stuff with result
    }).catch((err)=>{
      throw err
    })
  })
})

List Domain Specific Models


Description

TThis operation returns the list of domain-specific models that are supported by the Computer Vision API. Currently, the API only supports one domain-specific model: a celebrity recognizer.


Options

  {
    "Ocp-Apim-Subscription-Key": "A_Key"
    "request-origin":"<Choose-one-from-Supported-Regions>", // Required one only
  }

Function call

listDomainSpecificModels({
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"westus"
}).then((result)=>{
    // Domain content are now in the result
}).catch((err)=>{
  throw err
})

Example of getting List Domain Specific Models

const microsofComputerVision = require("microsoft-computer-vision")
microsofComputerVision.listDomainSpecificModels({
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"westus"
}).then((result)=>{
 
  console.log(JSON.stringify(result))        // {
                                              //   "models": [
                                              //       {
                                              //           "name": "celebrities",
                                              //           "categories": [
                                              //               "people_"
                                              //           ]
                                              //       }
                                              //   ],
                                              //   "requestId": "980399d9-c520-49b6-bf29-bbe30aae515e"
                                              // }
}).catch((err)=>{
  throw err
})

Recognize Domain Specific Content


Description

This operation recognizes content within an image by applying a domain-specific model. The list of domain-specific models that are supported by the Computer Vision API can be retrieved using the /models GET request. Currently, the API only provides a single domain-specific model: celebrities.

Two input methods are supported -- (1) Uploading an image binary or (2) specifying an image URL.


Options

{
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>", // Required one only
    "content-type": "application/json",
    "url": "image_url",
    "model": "{model}" // use listDomainSpecificModels() to get current available models
  }

Function call

recognizeDomainSpecificContent({
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>",
    "content-type": "application/json",
    "url": "image_url",
    "model": "{model}"
}).then((result)=>{
    // Domain content are now in the result
}).catch((err)=>{
  throw err
})

Example of passing image by URL

const microsofComputerVision = require("microsoft-computer-vision")
microsofComputerVision.recognizeDomainSpecificContent({
    "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
    "request-origin":"<Choose-one-from-Supported-Regions>",
    "content-type": "application/json",
    "url": "http://d.ibtimes.co.uk/en/full/377533/bill-gates.jpg",
    "model": "celebrities"
}).then((result)=>{
 
  console.log(JSON.stringify(result))      //   {
                                            //     "requestId": "055c5645-3ec0-4dc9-9da8-98d62a28a7c2",
                                            //     "metadata": {
                                            //         "width": 620,
                                            //         "height": 414,
                                            //         "format": "Jpeg"
                                            //     },
                                            //     "result": {
                                            //         "celebrities": [
                                            //             {
                                            //                 "name": "Bill Gates",
                                            //                 "faceRectangle": {
                                            //                     "left": 184,
                                            //                     "top": 80,
                                            //                     "width": 153,
                                            //                     "height": 153
                                            //                 },
                                            //                 "confidence": 0.9999932
                                            //             }
                                            //         ]
                                            //     }
                                            // }
}).catch((err)=>{
  throw err
})

Example of passing image by binary

// Suppose you want get model in /tests/image/RDSCTest.jpg
 
const microsofComputerVision = require("microsoft-computer-vision")
 
fs.readFile('/tests/image/RDSCTest.jpg', function(err, data) {
    microsofComputerVision.recognizeDomainSpecificContent({
      "Ocp-Apim-Subscription-Key": "<your-subscription-key>",
      "request-origin":"<Choose-one-from-Supported-Regions>",
      "model": "celebrities",
      "content-type": "application/octet-stream",
      "body": data
    }).then((result) => {
      console.log(JSON.stringify(result))      //   {
                                                //     "requestId": "055c5645-3ec0-4dc9-9da8-98d62a28a7c2",
                                                //     "metadata": {
                                                //         "width": 620,
                                                //         "height": 414,
                                                //         "format": "Jpeg"
                                                //     },
                                                //     "result": {
                                                //         "celebrities": [
                                                //             {
                                                //                 "name": "Bill Gates",
                                                //                 "faceRectangle": {
                                                //                     "left": 184,
                                                //                     "top": 80,
                                                //                     "width": 153,
                                                //                     "height": 153
                                                //                 },
                                                //                 "confidence": 0.9999932
                                                //             }
                                                //         ]
                                                //     }
                                                // }
  }
    }).catch((err)=>{
      throw err
    })
})

Example of passing image by multipart/form-data

 
// here use multer as multipart/form-data handler
 
const microsofComputerVision = require("microsoft-computer-vision")
const myKey = "xxxxxxxxx"
const path = require('path')
const express = require('express')
const app = express()
const multer  = require('multer')
const storage = multer.memoryStorage()
const upload = multer({ storage: storage }).single('image')
 
app.post('/upload',  (req, res, next) => {
  upload(req, res, function (err) {
    if (err) {
      // An error occurred when uploading
      console.log(err)
      return
    }
 
    // Everything went fine
    microsofComputerVision.recognizeDomainSpecificContent({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "multipart/form-data",
      "model": "celebrities",
      "body": req.file,
      "request-origin":"westus"
    }).then((result) => {
        // do stuff with result
    }).catch((err)=>{
      throw err
    })
  })
})

License

This library is licensed under MIT. Full license text is available in COPYING.

Contributing

See CONTRIBUTING.

Package Sidebar

Install

npm i microsoft-computer-vision

Weekly Downloads

0

Version

0.4.2

License

MIT

Unpacked Size

453 kB

Total Files

28

Last publish

Collaborators

  • xiaoyuz2011