-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathFacePPClient.php
99 lines (80 loc) · 2.5 KB
/
FacePPClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
define ("F_DEBUG_MODE", false);
class FacePPClient
{
private $api_server_url;
private $auth_params;
public function __construct($api_key, $api_secret)
{
$this->api_server_url = "http://api.faceplusplus.com/";
$this->auth_params = array();
$this->auth_params['api_key'] = $api_key;
$this->auth_params['api_secret'] = $api_secret;
}
//////////////////////////////////////////////////////////
// public mathods
//////////////////////////////////////////////////////////
public function person_create($person_name)
{
return $this->call("person/create", array("person_name" => $person_name));
}
public function person_add_face($face_id, $person_name)
{
return $this->call("person/add_face", array("person_name" => $person_name,
"face_id" => $face_id));
}
public function recognition_train($group_name)
{
return $this->call("recognition/train", array("group_name" => $group_name,
"type" => "recognize"));
}
public function face_detect($urls = null)
{
return $this->call("detection/detect", array("url" => $urls));
}
public function recognition_recognize($url, $group_name)
{
return $this->call("recognition/recognize", array("url" => $url,
"group_name" => $group_name));
}
public function group_create($group_name)
{
return $this->call("group/create", array("group_name" => $group_name));
}
public function group_add_person($person_name, $group_name)
{
return $this->call("group/add_person", array("person_name" => $person_name,
"group_name" => $group_name));
}
public function info_get_session($session_id) {
return $this->call("info/get_session", array("session_id" => $session_id));
}
//////////////////////////////////////////////////////////
// private mathods
//////////////////////////////////////////////////////////
protected function call($method, $params = array())
{
$params = array_merge($this->auth_params, $params);
$url = $this->api_server_url . "$method?".http_build_query($params);
if (F_DEBUG_MODE)
{
echo "REQUEST: $url" . "\n";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$result = null;
if (!empty($data))
{
if (F_DEBUG_MODE)
{
echo "RETURN: " . $data . "\n";
}
$result = json_decode($data);
}
return $result;
}
}
?>