代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function saveNewImageToFaceCollection(elem) {
let subject = encodeURIComponent(document.getElementById("subject").value);
let apiKey = document.getElementById("apiKey").value;
let formData = new FormData();
let photo = elem.files[0];
formData.append("file", photo);
fetch('http://localhost:8000/api/v1/recognition/faces/?subject=' + subject,
{
method: "POST",
headers: {
"x-api-key": apiKey
},
body: formData
}
).then(r => r.json()).then(
function (data) {
console.log('New example was saved', data);
})
.catch(function (error) {
alert('Request failed: ' + JSON.stringify(error));
});
}
function recognizeFace(elem) {
let apiKey = document.getElementById("apiKey").value;
let formData = new FormData();
let photo = elem.files[0];
formData.append("file", photo);
fetch('http://localhost:8000/api/v1/recognition/recognize',
{
method: "POST",
headers: {
"x-api-key": apiKey
},
body: formData
}
).then(r => r.json()).then(
function (data) {
document.getElementById("result").innerHTML = JSON.stringify(data);
})
.catch(function (error) {
alert('Request failed: ' + JSON.stringify(error));
});
}
</script>
<title>test</title>
</head>
<body>
<label for="apiKey">API key:</label><input id="apiKey" />
<div></div>
<label for="subject">Subject:</label><input id="subject" />
<div>Click to add photo:</div>
<input type=file id="newFace" onchange="saveNewImageToFaceCollection(this)" />
<div>Click to recognize photo</div>
<input type=file id="recognizeFace" onchange="recognizeFace(this)" />
<div>Result:</div>
<div id="result"></div>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。