api_server_url = "http://apitest.cn.faceplusplus.com/"; $this->auth_params = array(); $this->auth_params['api_key'] = FACEKEY; $this->auth_params['api_secret'] = FACESECRET; } /** * 检测一张照片中的人脸信息(脸部位置、年龄、种族、性别等等)[通过URL提供图片 ] * @param string $urls 待检测图片的URL * @return Ambigous */ public function face_detect($urls = null) { return $this->post_call("detection/detect", array( "url" => $urls )); } /** * 检测给定人脸相应的面部轮廓,五官等关键点的位置 * @param string $face_id * @return Ambigous */ public function face_landmark($face_id = null) { return $this->post_call("detection/landmark", array( "face_id" => $face_id )); } /** * 检测一张照片中的人脸信息(脸部位置、年龄、种族、性别等等)[通过POST方法上传二进制数据] * @param string $urls * @return Ambigous */ public function face_detect_post($filename) { return $this->post_call("detection/detect", array( "img" => '@' . $filename )); } /** * 检测一张照片中的人脸信息(脸部位置、年龄、种族、性别等等)【通过URL提供图片】 * @param string $filename URL * @param string $offline_result 默认脸区域(四个点) * @return Ambigous */ public function face_detect_post_final($filename,$attribute="gender,age,race,smiling,glass,pose,landmark83p",$offline_result="[[72,35,172,135]]") { return $this->post_call("detection/detect", array( 'url' => $filename, 'attribute' => $attribute,//可以是none或者由逗号分割的属性列表。默认为gender, age, race, smiling。目前支持的属性包括:gender, age, race, smiling, glass, pose 'mode' => 'offline',//检测模式可以是normal(默认) 或者 oneface 。在oneface模式中,检测器仅找出图片中最大的一张脸。 'offline_result' => $offline_result, )); } // //////////////////////////////////////////////////////// // private mathods // //////////////////////////////////////////////////////// protected function post_call($method, $params = array()) { $params = array_merge($this->auth_params, $params); $url = $this->api_server_url . "$method"; if (DEBUG_MODE) { echo "REQUEST: $url?" . http_build_query($params) . "\n"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); $result = null; if (! empty($data)) { if (DEBUG_MODE) { echo "RETURN: " . $data . "\n"; } $result = json_decode($data); } return $result; } } ?>