当
涉及到jQuery时,我有点慢,因为我试图在这种语言中获得一些立足点。我目前正在使用FaceAPI,并且它运行得很好。在识别阶段,我有一个返回信息数组的 Ajax 调用。
$.ajax({
url: 'http://api.face.com/faces/recognize.json?&uids=all&namespace=camera_app&detector=Aggressive&',
data: formdata,
cache: false,
contentType: false,
processData: false,
dataType:"json",
type: 'POST',
success: function (data) {
photo = data.photos[0];
handleResult(photo)
},
但我最感兴趣的是被称为API的"UID",它将一个人的脸与他们的UID相匹配。我想知道的是,一旦返回 UID,是否可以放置时间戳并将其保存到我已设置的数据库中?[旁注:用户照片仅提交到 API,我不将它们保存在我的数据库中。我唯一保存的是用户的名字/姓氏和 UID。我只是不知道时间戳函数如何与返回变量一起工作。
我希望能够在以后提取返回该信息时匹配的 UID 和时间戳。
更新:
以下是向用户显示 UID 和准确性(置信度)的位置:
function handleResult(photo) {
console.log(photo)
var s = "<h2 class='results'>Account Information:</h2>";
if(photo.tags.length) {
var tag = photo.tags[0].uids[0];
s += "<p>";
//$('#result') .html ('Welcome Back:' + photo.uid + ',' + 'Confidence:' + photo.confidence);
if(tag.uid) s += "<li> User:" + tag.uid + "</li>";
if(tag.uid) s += "<li> Accuracy:" + tag.confidence + "%" + "</li>";
if(tag.uid == 0) s += "I got something, but the data wasn't clear. Sorry.";
} else {
s += "<p>Sorry, I didn't find any faces.</p>";
}
$("#result").html(s);
在这个阶段,我希望创建一个时间戳。
解决:
function handleResult(photo) {
console.log(photo)
var s = "<h2 class='results'>Account Information:</h2>";
var month = new Date().getMonth() + 1;
var day = new Date().getDate();
var hours = new Date().getHours();
var min = new Date().getMinutes();
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (min < 10)
min = "0" + min
if(photo.tags.length) {
var tag = photo.tags[0].uids[0];
s += "<p>";
//$('#result') .html ('Welcome Back:' + photo.uid + ',' + 'Confidence:' + photo.confidence);
if(tag.uid) s += "<li> User:" + tag.uid + "</li>";
if(tag.uid) s += "<li> Accuracy:" + tag.confidence + "%" + "</li>";
if(tag.uid) s += "<li> Timestamp:" + month + "/" + day + " " + hours + ":" + min + suffix + "</li>";
if(tag.uid == 0) s += "I got something, but the data wasn't clear. Sorry.";
} else {
s += "<p>Sorry, I didn't find any faces.</p>";
}
$("#result").html(s);
您可以使用
Date 函数在handleResult
回调中创建时间戳。
var timestamp = Math.round( new Date().getTime() / 1000 )