思路
首先要判断这张照片是否在文件中,得到你的APP_ID,API_KEY,SECRET_KEY,然后调用AipFace,将照片写成base64格式,再调用detect方法。如果正确会返回error_msg为SUCCESS。
代码
public function sdk(){
$file = './Uploads/3.jpg';
if(!file_exists($file)){
die ("文件不存在");
}
$dir = APP_PATH . '/face-sdk/';
require_once $dir . "AipFace.php";
$APP_ID = xxx;
$API_KEY = xxx;
$SECRET_KEY = xxx;
$client = new \AipFace($APP_ID, $API_KEY, $SECRET_KEY);
$image = file_get_contents($file);
$image = base64_encode($image);
// echo $image;
// exit;
$imageType = "BASE64";
$options = array();
// $options["face_field"] = "age";
$options["max_face_num"] = 6;
// $options["face_type"] = "LIVE";
$ret = $client->detect($image, $imageType,$options);
print_r($ret);
}