PHP实现人脸识别技术
这次人脸识别技术,是实现在微信端的,也就是说利用公众微信平台,调用第三的API来实现人脸识别这项技术的。
实现的思路:
首先呢,将收集的照片,建立一个照片库,然后利用在微信平台发送的照片,去到照片库进行匹配,那么怎么匹配呢?
这就要利用第三方的API了。
这个是收集信息,然后存储到信息库(包括图谱库)

部分代码:
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>上传到人脸信息库</title>
<link rel="stylesheet" href="./weui/dist/style/weui.min.css"/>
<style>
#preview, .img, img
{
width:79px;
height:79px;
}
</style>
</head>
<body>
<div class="hd" style="text-align:center;">
<h1 class="weui_cell_primary">上传到人脸信息库</h1>
</div>
<form action="up.php" method="post" enctype="multipart/form-data">
<div class="weui_cell">
<div class="weui_cell_hd"><label class="weui_label">姓名</label></div>
<div class="weui_cell_bd weui_cell_primary">
<input class="weui_input" type="text" name="username" placeholder="请输入联系人姓名"/>
</div>
</div>
<div class="weui_cell">
<div class="weui_cell_hd"><label class="weui_label">电话</label></div>
<div class="weui_cell_bd weui_cell_primary">
<input class="weui_input" type="text" name="number" pattern="[0-9]*" placeholder="请输入联系人电话号码"/>
</div>
</div>
<div class="weui_cell">
<div class="weui_cell_hd"><label class="weui_label">微信</label></div>
<div class="weui_cell_bd weui_cell_primary">
<input class="weui_input" type="text" name="weixin" placeholder="请输入联系人微信号"/>
</div>
</div>
<div class="weui_cell">
<div class="weui_cell_bd weui_cell_primary">
<div class="weui_uploader">
<div class="weui_uploader_hd weui_cell">
<div class="weui_cell_bd weui_cell_primary">图片上传</div>
</div>
<div class="weui_uploader_bd">
<ul class="weui_uploader_files">
<li class="weui_uploader_file" id="preview"></li>
</ul>
<div class="weui_uploader_input_wrp">
<input class="weui_uploader_input" type="file" name="pic" onchange="preview(this)" />
</div>
</div>
</div>
</div>
</div>
<input type="submit" value="提交" class="weui_btn weui_btn_primary" style="width:40%;"/>
</form>
</body>
<script type="text/javascript">
function preview(file){
var prevDiv = document.getElementById('preview');
if(file.files && file.files[0]){
var reader = new FileReader();
reader.onload = function(evt){
prevDiv.innerHTML = '<img src="' + evt.target.result + '" />';
}
reader.readAsDataURL(file.files[0]);
}else{
prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
}
}
</script>
</html>
分析照片
<?php
if(isset($_FILES['pic'])&&$_FILES['pic']['error'] == 0){
$name = mt_rand(100000,999999);
$ext = explode(".",$_FILES['pic']['name']);
$ext = end($ext);
$full = $name.".".$ext;
$rs = move_uploaded_file($_FILES['pic']['tmp_name'], './upload/'.$full);
if(!$rs){
exit('上传图片出错');
} //上传成功后,获取图片地址
$pic = 'http://yxhwxtest.applinzi.com/wx/upload/'.$full;
//$pic = 'http://yxhwxtest.applinzi.com/wx/upload/718204.jpg'; //人脸检测与分析
$api = 'http://apicn.faceplusplus.com/v2/detection/detect?api_key=3f2fd9843ac889c84f43de513bca05f2&api_secret=sDUH2FP2b3L4tSKQNHCCk17sUYsHW8HU&url='.$pic.'&attribute=glass,pose,gender,age,race,smiling'; //将json转换为数组
$rs = json_decode(file_get_contents($api),true); if(count($rs['face']) == 0){
exit('没有检测出人脸');
} $face_id = $rs['face'][0]['face_id']; //创建脸集
//$api='https://apicn.faceplusplus.com/v2/faceset/create?api_key=3f2fd9843ac889c84f43de513bca05f2&api_secret=sDUH2FP2b3L4tSKQNHCCk17sUYsHW8HU&faceset_name=renlianshibie&face_id='.$face_id; //将人脸加入到脸集中
$api = 'https://apicn.faceplusplus.com/v2/faceset/add_face?api_secret=sDUH2FP2b3L4tSKQNHCCk17sUYsHW8HU&face_id='.$face_id.'&api_key=3f2fd9843ac889c84f43de513bca05f2&faceset_name=renlianshibie'; $rs = json_decode(file_get_contents($api),true); if($rs['success'] == 0){
exit('加入脸集失败');
}else{
//训练脸集
$api = 'https://apicn.faceplusplus.com/v2/train/search?api_key=3f2fd9843ac889c84f43de513bca05f2&api_secret=sDUH2FP2b3L4tSKQNHCCk17sUYsHW8HU&faceset_name=renlianshibie';
$rs = file_get_contents($api);
//p($rs);
exit('加入脸集成功');
}
}
//调试输出函数
function p($var){
if(is_bool($var)){
var_dump($var);
}else if(is_null($var)){
var_dump(NULL);
}else{
echo "<pre style='position:relative;z-index:1000;padding:10px;border-radius:5px;background:#F5F5F5;border:1px solid #aaa;font-size:14px;line-height:18px;opacity:0.9;'>".print_r($var,true)."</pre>";
}
}
?>
收集信息完成后
在微信平台上回复 你要找的人的照片

这是服务器接收到图片进行响应的代码:
//接受图片进行回复
if(strtolower($postObj->MsgType=='image')){
$pic = $postObj->PicUrl;
//检测人脸和分析
$api = 'http://apicn.faceplusplus.com/v2/detection/detect?api_key=3f2fd9843ac889c84f43de513bca05f2&api_secret=sDUH2FP2b3L4tSKQNHCCk17sUYsHW8HU&url='.$pic.'&attribute=glass,pose,gender,age,race,smiling';
$rs = json_decode(file_get_contents($api),true);
if(count($rs['face'])==0){
$cont = "没有检测到人脸";
}
$face_id = $rs['face'][0]['face_id']; //得到人脸,到脸集中去找相似的脸
$api = 'https://apicn.faceplusplus.com/v2/recognition/search?api_key=3f2fd9843ac889c84f43de513bca05f2&api_secret=sDUH2FP2b3L4tSKQNHCCk17sUYsHW8HU&faceset_name=renlianshibie&key_face_id='.$face_id; $rs = json_decode(file_get_contents($api),true); //$ps=[]; foreach($rs['candidate'] as $v) {
if( intval($v['similarity']) > 60) {
$ps[] = $v['face_id'];
}
} if(empty($ps)){
$cont = "找到相似的人";
}else{
$fids = implode(',', $ps);
$api = 'https://apicn.faceplusplus.com/v2/info/get_face?api_key=3f2fd9843ac889c84f43de513bca05f2&api_secret=sDUH2FP2b3L4tSKQNHCCk17sUYsHW8HU&face_id='.$fids; $rs = json_decode(file_get_contents($api),true); if(count($rs['face_info'])==0){
$cont = '没有找到相识的人';
}else{
$cont = '找到相似的人'."\n";
foreach ($rs['face_info'] as $v) {
$cont .= $v['url']."\n";
}
}
} //回复用户消息
$toUser = $postObj->FromUserName;
$fromUser = $postObj->ToUserName;
$time = time();
$content = $cont;
$msgType = 'text';
$template = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$info = sprintf($template,$toUser,$fromUser,$time,$msgType,$content);
echo $info;
}
然后,服务器就会返回,相应匹配到的信息。
返回的相应照片

然后就是实现了,人脸匹配的功能。
调用API的第三方平台:http://www.faceplusplus.com.cn/demo-detect/
代码下载:http://download.csdn.net/detail/yxhbk/9629866
PHP实现人脸识别技术的更多相关文章
- face ++ 人脸识别技术初步
网站地址: https://console.faceplusplus.com.cn/documents/5671791主要有 1 人脸识别技术 2 人体识别技术 ...
- 旷视科技 -- Face++ 世界最大的人脸识别技术平台
旷视科技 -- Face++ 世界最大的人脸识别技术平台: https://www.megvii.com/
- 人脸识别技术大总结(1):Face Detection & Alignment
http://blog.jobbole.com/85783/ 首页 最新文章 IT 职场 前端 后端 移动端 数据库 运维 其他技术 - 导航条 - 首页 最新文章 IT 职场 前端 - Ja ...
- 基于 HTML5 的人脸识别技术
基于 HTML5 的人脸识别技术 https://github.com/auduno/headtrackr/
- 3D动态人脸识别技术分析——世纪晟人脸识别实现三维人脸建模
- 目录 - 国内3D动态人脸识别现状概况 - 新形势下人脸识别技术发展潜力 - 基于深度学习的3D动态人脸识别技术分析 1. 非线性数据建模方法 2. 基于3D变形模型的人脸建模 - 案例结合——世 ...
- 人脸识别技术大总结1——Face Detection & Alignment
搞了一年人脸识别,寻思着记录点什么,于是想写这么个系列,介绍人脸识别的四大块:Face detection, alignment, verification and identification(re ...
- 基于百度AI人脸识别技术的Demo
编写demo之前首先浏览官方API:http://ai.baidu.com/docs#/Face-API/top 下面是源码: package com.examsafety.test; import ...
- ios OpenCv的配置和人脸识别技术
作为一个好奇心非常重的人,面对未知的世界都想去一探到底. 于是做了个人脸识别的demo. 眼下国内的关于opencv技术文章非常少.都是互相抄袭.关键是抄个一小部分还不全.时间又是非常久之前的了,和如 ...
- paper 97:异质人脸识别进展的资讯
高新波教授团队异质人脸图像识别研究取得新突破,有望大大降低刑侦过程人力耗费并提高办案效率 近日,西安电子科技大学高新波教授带领的研究团队,在异质人脸图像识别研究领域取得重要进展,其对香 ...
随机推荐
- UVA1422-Processor(二分法+优先队列)
option=com_onlinejudge&Itemid=8&category=512&page=show_problem&problem=4168"> ...
- Ipython基础功能
ipython:交互式的python命令行 直接在终端敲命令即可进入 安装:pip install ipython 使用:在终端敲“ipython” 与python解释器的使用方法一致 TAB键自动补 ...
- 网页编程-django前传
1.js正则表达式 http://www.cnblogs.com/wupeiqi/articles/5602773.html test - 判断字符串是否符合规定的正则 正则表达式: rep = ...
- 宜人贷蜂巢ELK Stack之elasticsearch权限探索
前言 上文<宜人贷蜂巢API网关技术解密之Netty使用实践>提到了,API网关“承外对内”,将外部请求,转发到内部各个抓取服务.在网关中,不仅可以做鉴权.加解密.路由.限流功能:如果想了 ...
- Angularv4入门篇1
国庆时按照官网的tutorial写了遍官方示例,一知半解,不明白angular的服务的服务为何要单独抽离出来.angular应用是如何启用的.近期打算看下angular的文档部分,然后梳理遍以理解an ...
- iOS用户是否打开APP通知开关跳转到系统的设置界面
1.检测用户是否打开推送通知 /** 系统通知是否打开 @return 是否打开 */ //检测通知是否打开iOS8以后有所变化 所以需要适配iOS7 + (BOOL)openThePushNoti ...
- kubernetes-handbook 阅读笔记
文档地址 https://jimmysong.io/kubernetes-handbook/concepts/ Pod是在Kubernetes集群中运行部署应用或服务的最小单元,它是可以支持多容器的. ...
- EasyDarwin添加自定义的服务模块EasyMyModule
EasyDarwin模块的要求 每个QTSS模块必须实现两个方法函数: 一个Main入口函数,服务器在启动的时候将调用这个方法函数,来对您开发的模块所在的QTSS stub库进行初始化. 一个Disp ...
- Spring整合Struts2的方法
一.基本支持 通常我们整合Spring和struts2的目的是让Spring来管理struts2的控制器.也就是说把Action交由Spring来管理,利用IOC的特性把Action注入到业务逻辑中. ...
- 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:679 解决:357 题目描述: One of the first users of BIT's new supercomputer was ...