Slide 45
Slide 45 text
Computer Vision API
44
function onImageUrlButtonClick() {
$('#imageUrlButton').attr("disabled", true);
$('#result').html('');
$('#image').html('');
var endpoint
= ’https://japanwest.api.cognitive.microsoft.com/vision/v1
.0’;
var subscriptionKey = ‘[SubscriptionKey]’;
var params = {
‘visualFeatures’: ‘Description, Faces’,
‘details’: "",
‘language’: ‘en’,
};
var imageUrl = $('#imageUrlTextBox').val();
$.ajax({
url: endpoint + ’/analyze?’ + $.param(params),
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader(‘Content-
Type’, ’application/json’);
xhrObj.setRequestHeader(‘Ocp-Apim-
Subscription-Key’, subscriptionKey);
}, type: ’POST’,
data: '{"url": ' + '"' + imageUrl + '"}',
success: function (predictions) {
$('#result').html(
predictionsToHtml(predictions));
var captionText = getCaptionText(
predictions.description.captions);
$('#image').html(imageUrlToHtml(
imageUrl, captionText));
},
error: function () {
$('#result').html('エラー: 結果を取得で
きませんでした。');
}, complete: function () {
$('#imageUrlButton').attr("disabled", false);
}
});
}