【发布时间】:2016-01-07 13:52:23
【问题描述】:
我正在构建一个应用程序来检查用户是否按照提供的说明拍照并匹配面部识别。
我有 8 条指令供用户使用,例如检查他们是否在拍照时微笑,因为我们的面部识别是通过在线 API 'Skybiometry' 实现的。所以我们必须从它的 JSON 值中获取相应的值,如下所示,在另一个 html 文件中,如果结果不成功,我需要调用 VerifyFace() 函数并在另一个 javascript 文件中获取消息和结果变量。我将该函数称为VerifyFace();,然后是result; 和message;。但是代码不起作用。
function ValuesToCheck(){
Msgs = Msgs();
RandomMsg = RandomMsg();
if (RandomMsg == Msgs[0] || RandomMsg == Msgs[1]){
var check = photos[0].tags[0].attributes[0].glasses[0];
} else if (RandomMsg == Msgs[2] || RandomMsg == Msgs[3]) {
var check = photos[0].tags[0].attributes[0].smiling[0];
} else if (RandomMsg == Msgs[4] || RandomMsg == Msgs[5]) {
var check = photos[0].tags[0].attributes[0].lips[0];
} else if (RandomMsg == Msgs[6] || RandomMsg == Msgs[7]) {
var check = photos[0].tags[0].attributes[0].eyes[0];
}
check = "facesDet." + check;
return check;
}
var result = "Unsuccessful";
var message = "You didn't follow the instruction, please try again.";
function VerifyFace(){
Msgs = Msgs();
RandomMsg = RandomMsg();
check = ValuesToCheck();
var value = check + ".value";
var confidence = check + ".confidence";
if (RandomMsg == Msgs[0] && value == true && confidence >= 50){
console("Users followed the instruction!");
} else {
result;
message;
}
if (RandomMsg == Msgs[1] && value == false && confidence < 50){
console("Users followed the instruction!");
} else {
result;
message;
}
if (RandomMsg == Msgs[2] && value == true && confidence >= 50){
console("Users followed the instruction!");
} else {
result;
message;
}
}
以下是“Skybiometry”的 JSON 输出:
{
"photos" : [
{
"url" : "http://tinyurl.com/673cksr",
"pid" : "F@0c95576847e9cd7123f1e304476b59ae_59ec9bb2ad15f",
"width" : 375,
"height" : 409,
"tags" : [
{
"tid" : "TEMP_F@0c95576847e9cd7123f1e304b1dcbe53_59ec9bb2ad15f_56.53_40.83_0_1",
"recognizable" : true,
"confirmed" : false,
"manual" : false,
"width" : 30.67,
"height" : 28.12,
"center" : { "x" : 56.53, "y" : 40.83},
"eye_left" : { "x" : 66.93, "y" : 33.99},
"eye_right" : { "x" : 51.73, "y" : 33.99},
"yaw" : -16,
"roll" : 0,
"pitch" : 0,
"attributes" : {
"face" : { "value" : "true", "confidence" : 82 },
"gender" : { "value" : "female", "confidence" : 80 },
"glasses":{"value" : "true", "confidence" : 100},
"dark_glasses":{"value" : "true", "confidence" : 72},
"smiling":{"value" : "false", "confidence" : 35}
}
}
]
}
],
"status" : "success",
"usage" : {
"used" : 1,
"remaining" : 99,
"limit" : 100,
"reset_time_text" : "Fri, 21 September 2012 12:57:19 +0000",
"reset_time" : 1348232239
}
}
【问题讨论】:
-
表达式
result;和message;实际上并没有做任何事情。是什么让您认为它不起作用。 -
请缩进您的代码。我们无法阅读它(我怀疑你也可以)。
-
尝试“调试”你的程序。 SO 并不擅长调试程序。你的调试器在这方面要好得多。见ericlippert.com/2014/03/05/how-to-debug-small-programs。
-
console('...')也可能会产生错误 -
您好,很抱歉没有正确格式化它,我正在缩进代码来发布它,忽略了整洁的格式。刚刚编辑整齐,如果有其他需要编辑的地方请再次指出。
标签: javascript json