微软认知服务识别名人和地标
code:
<!DOCTYPE html>
<html>
<head>
<title>识别名人和地标</title>
<script src="https://yunewstoragetest.blob.core.chinacloudapi.cn/jslib/jquery-2.2.2.min.js"></script>
</head>
<body>
<script type="text/javascript">
function processImage() {
var subscriptionKey = "<Computer API key>";
var myselect=document.getElementById("selectid");
var index=myselect.selectedIndex;
var uriBase;
if(index == 1)
{
uriBase = "https://api.cognitive.azure.cn/vision/v1.0/models/landmarks/analyze";
}
else
{
uriBase = "https://api.cognitive.azure.cn/vision/v1.0/models/celebrities/analyze";
}
var sourceImageUrl = document.getElementById("inputImage").value;
document.querySelector("#sourceImage").src = sourceImageUrl;
// Perform the REST API call.
$.ajax({
url: uriBase,
// Request headers.
beforeSend: function(xhrObj) {
xhrObj.setRequestHeader("Content-Type", "application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
},
type: "POST",
// Request body.
data: '{"url": ' + '"' + sourceImageUrl + '"}',
})
.done(function(data) {
// Show formatted JSON on webpage.
$("#responseTextArea").val(JSON.stringify(data, null, 2));
})
.fail(function(jqXHR, textStatus, errorThrown) {
// Display error message.
var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
errorString += (jqXHR.responseText === "") ? "" : jQuery.parseJSON(jqXHR.responseText).message;
alert(errorString);
});
};
</script>
<h1>识别名人和地标</h1>
<select id="selectid">
<option value="celebrities">名人</option>
<option value="landmarks">地标</option>
</select>
<br><br>
输入图片URL:<input type="text" name="inputImage" id="inputImage" value="" />
<button onclick="processImage()">执行分析</button>
<br><br>
<div id="wrapper" style="width:1020px; display:table;">
<div id="jsonOutput" style="width:600px; display:table-cell;">
分析结果:
<br><br>
<textarea id="responseTextArea" class="UIInput" style="width:480px; height:300px;"></textarea>
</div>
<div id="imageDiv" style="width:420px; display:table-cell;">
原图片:
<br><br>
<img id="sourceImage" width="400" />
</div>
</div>
</body>
</html>
测试结果:
更多参考链接:
Recognize Domain Specific Content