This package has been deprecated

Author message:

This package is deprecated in favor of @azure/cognitiveservices-computervision which works both on node.js and browsers

azure-cognitiveservices-computervision
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

Microsoft Azure SDK for Node.js - Cognitive Services Computer Vision

This project provides a Node.js package that makes it easy to work with the Microsoft Azure Cognitive Services Computer Vision API. Right now it supports:

  • Node.js version: 6.x or higher

How to Install

npm install azure-cognitiveservices-computervision

How to use

Create a Cognitive Services Account(ex. Computer Vision)

  const msRestAzure = require('ms-rest-azure');
  const CognitiveServicesManagement = require('azure-arm-cognitiveservices');
  const SubscriptionId = 'your-subscription-key';
  const ResourceGroup = 'your-resource-group-name';
  const ResourceName = 'resource-name';
  let client;
  let createAccount = msRestAzure.interactiveLogin().then((credentials) => {
    client = new CognitiveServicesManagement(credentials, SubscriptionId);
    return client.accounts.create(ResourceGroup, ResourceName, {
      sku: {
        name: 'F0'
      },
      kind: 'ComputerVision',
      location: 'westus',
      properties: {}
    });
  }).catch((err) => {
    console.log('An error ocurred');
    console.dir(err, {depth: null, colors: true});
  });

List the keys from the created account

  let serviceKey;
  createAccount.then((result) => {
    return client.accounts.listKeys(ResourceGroup, ResourceName);
  }).then((result) => {
    serviceKey = result.key1;
    console.log(result.key2);
  }).catch((err) => {
    console.log('An error ocurred');
    console.dir(err, {depth: null, colors: true});
  });

Create credentials

const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;
 
// Creating the Cognitive Services credentials
// This requires a key corresponding to the service being used (i.e. text-analytics, etc)
let credentials = new CognitiveServicesCredentials(serviceKey);

Computer Vision API

const ComputerVisionClient = require('azure-cognitiveservices-computervision');
 
let client = new ComputerVisionClient(credentials, 'https://westus.api.cognitive.microsoft.com');
let fileStream = require('fs').createReadStream('pathToSomeImage.jpg');
client.analyzeImageInStreamWithHttpOperationResponse(fileStream, {
  visualFeatures: ['Categories', 'Tags', 'Description']
}).then((response) => {
  console.log(response.body.tags);
  console.log(response.body.description.captions[0]);
}).catch((err) => {
  throw err;
});

More Detailed Information

https://azure.microsoft.com/en-us/try/cognitive-services/ under "Vision"

Related Projects

Impressions

Keywords

Install

npm i azure-cognitiveservices-computervision

DownloadsWeekly Downloads

6

Version

4.0.0

License

MIT

Unpacked Size

456 kB

Total Files

48

Last publish

Collaborators

  • windowsazure