php开发人脸识别的api接口

上传人:第*** 文档编号:31081704 上传时间:2018-02-04 格式:DOC 页数:4 大小:61.50KB
返回 下载 相关 举报
php开发人脸识别的api接口_第1页
第1页 / 共4页
php开发人脸识别的api接口_第2页
第2页 / 共4页
php开发人脸识别的api接口_第3页
第3页 / 共4页
php开发人脸识别的api接口_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《php开发人脸识别的api接口》由会员分享,可在线阅读,更多相关《php开发人脸识别的api接口(4页珍藏版)》请在金锄头文库上搜索。

1、php 开发人脸识别的 api 接口作者:来源:互联网日期:2013-11-14 16:20:25 收藏评论:( 0 )阅读:1982在网上发现一个 PHP 编写的人脸识别的 API,试了一下还不错,这里推荐给大家,有兴趣的可以研究研究。首先,检测出三张输入图片中的 Face。然后,使用这三个 Face 各自创建 1 个新的 Person。这三个 Person 将构建一个新的 Group 以作为候选的识别库。最后,输入一张新 Image,并在已构建的 Group 中识别这个新 Image 中的 Face。创建新的 Person待识别图片首先需要经过初步检测,找出图片中 Face 的位置及属性。

2、然后,再使用 API 中的 Person 管理创建新的 Person。12345678910111213141516171819202/ the list of person_name to train and identify for$person_names = array(1, 2, 3);/ store the face_ids obtained by detection/detect API$face_ids = array();/ register new people, detect facesforeach ($person_names as $person_name)dete

3、ct($api, $person_name, $face_ids);/* create new person, detect faces from persons image_url*/function detect(&$api, $person_name, &$face_ids)/ obtain photo_url to train$url = getTrainingUrl($person_name);/ detect faces in this photo$result = $api-face_detect($url);/ skip errorsif (empty($result-face

4、)return false;/ skip photo with multiple faces (we are not sure which face to train)if (count($result-face) 1)return false;/ obtain the face_id$face_id = $result-face0-face_id;$face_ids = $face_id;/ delete the person if exists$api-person_delete($person_name);/ create a new person for this face122232

5、42526272829303132333435$api-person_create($person_name);/ add face into new person$api-person_add_face($face_id, $person_name);构建新的 Group注册一个新的 Group,并将之前创建的 Person 加入这个 Group。1234567891011/ the name of group for testing$group = sample_group;/ generate a new group, add people into groupcreate_group(

6、$api, $group, $person_names);/* generate a new group with group_name, add all people into group*/function create_group(&$api, $group_name, $person_names)/ delete the group if exists12131415161718$api-group_delete($group_name);/ create new group$api-group_create($group_name);/ add new person into the

7、 groupforeach ($person_names as $person_name)$api-group_add_person($person_name, $group_name);训练识别模型对刚创建的 group,调用/train/identify 来训练识别特征以待识别。(注意:/train/identify 是一个异步方法,因此在调用 train 函数后我们需要等待训练完毕才能继续执行后续代码。)1234567891011121314151617181920212223242526272829/ generate training model for grouptrain($ap

8、i, $group);/* train identification model for group*/function train(&$api, $group_name)/ train model$session = $api-train_identify($group_name);if (empty($session-session_id)/ something went wrong, skipreturn false;$session_id = $session-session_id;/ wait until training process donewhile ($session=$a

9、pi-info_get_session($session_id)sleep(1);if (!empty($session-status) if ($session-status != INQUEUE)break;/ donereturn true;识别新图中的 Face在对新图中的 Face 进行以上提及的检测,注册和训练之后,我们就可以在已构建 Group 中识别新图中出现的 Face 了:123456789101112131415161718192021222324252627282930/ finally, identify people in the groupidentify($ap

10、i, $person_names0, $group);/* identify a person in group*/function identify(&$api, $person_name, $group_name)/ obtain photo_url to identify$url = getPhotoUrl($person_name);/ recoginzation$result = $api-recognition_identify($url, $group_name);/ skip errorsif (empty($result-face)return false;/ skip ph

11、oto with multiple facesif (count($result-face) 1)return false;$face = $result-face0;/ skip if no person returnedif (count($face-candidate) candidate as $candidate)echo $candidate-person_name was found in $group_name with .confidence $candidate-confidencen;完整 PHP 代码可于此处下载(需要修改 api_key, api_secret, getTrainingUrl, getPhotoUrl 后才能正常运行)

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号