使用Face.com API进行人脸识别

时间:2011-07-18 10:40:05

标签: php json parsing

我一直在使用face.com API在PHP中进行面部识别。我能够将图像与命名空间进行比较,并将我返回的数据返回给我,我认为这是一个JSON字符串。问题是,我在解析它时遇到了麻烦。这是我的代码:

<?php

require_once("FaceRestClient.php");

$apikey = "API";
$apisecret = "SECRET";

$im1 = "http://zbrowntechnology.com/social1/20110718014242.jpg";

$api = new FaceRestClient($apikey, $apisecret);

$result = $api->faces_recognize(array($im1), "all@zach42047");

?>

结果返回以下数据,但仅当我使用var_dump($ result)时; :

object(stdClass)#2 (3) { ["photos"]=> array(1) { [0]=> object(stdClass)#3 (5) { ["url"]=> string(54) "http://zbrowntechnology.com/social1/20110718014242.jpg" ["pid"]=> string(67) "F@5a0af17100c8d0d3bb018bf2e10c840f_b5a43c71a66cc5f474c7eaf4927b93b1" ["width"]=> int(320) ["height"]=> int(240) ["tags"]=> array(1) { [0]=> object(stdClass)#4 (25) { ["tid"]=> string(88) "TEMP_F@5a0af17100c8d0d3bb018bf2e10c840f_b5a43c71a66cc5f474c7eaf4927b93b1_54.06_42.08_1_0" ["recognizable"]=> bool(true) ["threshold"]=> int(65) ["uids"]=> array(1) { [0]=> object(stdClass)#5 (2) { ["uid"]=> string(19) "ZachBrown@zach42047" ["confidence"]=> int(98) } } ["gid"]=> NULL ["label"]=> string(0) "" ["confirmed"]=> bool(false) ["manual"]=> bool(false) ["tagger_id"]=> NULL ["width"]=> float(39.38) ["height"]=> float(52.5) ["center"]=> object(stdClass)#6 (2) { ["x"]=> float(54.06) ["y"]=> float(42.08) } ["eye_left"]=> object(stdClass)#7 (2) { ["x"]=> int(45) ["y"]=> float(29.73) } ["eye_right"]=> object(stdClass)#8 (2) { ["x"]=> float(65.73) ["y"]=> float(29.86) } ["mouth_left"]=> object(stdClass)#9 (2) { ["x"]=> float(48.33) ["y"]=> float(55.14) } ["mouth_center"]=> object(stdClass)#10 (2) { ["x"]=> float(56.66) ["y"]=> float(55.97) } ["mouth_right"]=> object(stdClass)#11 (2) { ["x"]=> float(63.53) ["y"]=> float(54.29) } ["nose"]=> object(stdClass)#12 (2) { ["x"]=> float(57.52) ["y"]=> float(46.32) } ["ear_left"]=> NULL ["ear_right"]=> NULL ["chin"]=> NULL ["yaw"]=> float(14.15) ["roll"]=> float(0.26) ["pitch"]=> float(-3.41) ["attributes"]=> object(stdClass)#13 (4) { ["face"]=> object(stdClass)#14 (2) { ["value"]=> string(4) "true" ["confidence"]=> int(63) } ["gender"]=> object(stdClass)#15 (2) { ["value"]=> string(4) "male" ["confidence"]=> int(48) } ["glasses"]=> object(stdClass)#16 (2) { ["value"]=> string(5) "false" ["confidence"]=> int(12) } ["smiling"]=> object(stdClass)#17 (2) { ["value"]=> string(5) "false" ["confidence"]=> int(96) } } } } } } ["status"]=> string(7) "success" ["usage"]=> object(stdClass)#18 (5) { ["used"]=> int(0) ["remaining"]=> int(5000) ["limit"]=> int(5000) ["reset_time_text"]=> string(31) "Mon, 18 Jul 2011 11:38:26 +0000" ["reset_time"]=> int(1310989106) } }

我需要获取 uid 置信度数据。

我从昨晚(现在早上6点)开始研究这几个小时。这就是我能够获得返回数据的方式。我尝试使用JSON进行解码,但我仍然无法获得所需的数据。

2 个答案:

答案 0 :(得分:2)

foreach($result->photos as $photo) {
    foreach($photo->tags as $tag) {
        foreach($tag->uids as $uid) {
            echo $uid->uid . ' ' . $uid->confidence;
        }
    }
}

答案 1 :(得分:0)

它是一个数组。

foreach($result["photos"] as $photo) //Its an array of photos
  echo $photo["uid"] . " " . $photo["confidence"]; //each photo has the attributes.