Zac Brown
Zac Brown

Reputation: 6093

Face Recognition with Face.com API

I have been playing around with Facial recognition in PHP via the face.com API. I am able to compare an image with a namespace and get the data returned to me in what I think is a JSON string. The problem is, I'm having trouble parsing it. Here is my code:

<?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");

?>

Result returns the following data, but only when I use 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) } }

I need to get the uid and confidence data.

I have been researching this for hours, since 11 last night (6 am now).That is how I am able to get the data returned. I tried using JSON to decode, but I still couldn't get the data I needed.

Upvotes: 0

Views: 1118

Answers (2)

Salman Arshad
Salman Arshad

Reputation: 272256

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

Upvotes: 2

Vinoth Gopi
Vinoth Gopi

Reputation: 734

Its an array.

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

Upvotes: 0

Related Questions