Skip to content

Commit fd2c12d

Browse files
authored
Adding analyze image sample
1 parent 547940c commit fd2c12d

File tree

2 files changed

+49
-111
lines changed

2 files changed

+49
-111
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict'
5+
6+
const request = require('request')
7+
8+
/**
9+
* This sample uses the Computer Vision API to analyze a remote image.
10+
* It returns image properties such as categories, description (tags), color, and size.
11+
*
12+
* Computer Vision API - v2 .1:
13+
* https: //westus.dev.cognitive.microsoft.com/docs/services/5cd27ec07268f6c679a3e641/operations/56f91f2e778daf14a499f20d
14+
*/
15+
16+
// Add your Computer Vision subscription key and endpoint to your environment variables.
17+
let subscriptionKey = process.env['COMPUTER_VISION_SUBSCRIPTION_KEY']
18+
let endpoint = process.env['COMPUTER_VISION_ENDPOINT'] + '/vision/v2.1/analyze'
19+
20+
// Image to be analyzed; you may use your own URL image.
21+
const url =
22+
'https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/objects.jpg'
23+
24+
// Request parameters.
25+
const params = {
26+
'visualFeatures': 'Categories,Description,Color',
27+
'details': '',
28+
'language': 'en'
29+
}
30+
31+
// Options
32+
const options = {
33+
uri: endpoint,
34+
qs: params,
35+
body: '{"url": ' + '"' + url + '"}',
36+
headers: {
37+
'Content-Type': 'application/json',
38+
'Ocp-Apim-Subscription-Key' : subscriptionKey
39+
}
40+
}
41+
42+
// Make the request.
43+
request.post(options, (error, response, body) => {
44+
console.error('error:', error)
45+
console.log('statusCode:', response && response.statusCode)
46+
console.log('original image:', url.substring(url.lastIndexOf('/') + 1))
47+
console.log()
48+
console.log(JSON.stringify(JSON.parse(body), null, 2))
49+
})

nodejs/Vision/RecognizeText.js

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)