这次人脸识别技术,是实现在微信端的,也就是说利用公众微信平台,调用第三的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实现人脸识别技术的更多相关文章

  1. face ++ 人脸识别技术初步

    网站地址: https://console.faceplusplus.com.cn/documents/5671791主要有        1  人脸识别技术         2    人体识别技术  ...

  2. 旷视科技 -- Face++ 世界最大的人脸识别技术平台

    旷视科技 -- Face++ 世界最大的人脸识别技术平台: https://www.megvii.com/

  3. 人脸识别技术大总结(1):Face Detection & Alignment

    http://blog.jobbole.com/85783/     首页 最新文章 IT 职场 前端 后端 移动端 数据库 运维 其他技术 - 导航条 - 首页 最新文章 IT 职场 前端 - Ja ...

  4. 基于 HTML5 的人脸识别技术

    基于 HTML5 的人脸识别技术 https://github.com/auduno/headtrackr/

  5. 3D动态人脸识别技术分析——世纪晟人脸识别实现三维人脸建模

    - 目录 - 国内3D动态人脸识别现状概况 - 新形势下人脸识别技术发展潜力 - 基于深度学习的3D动态人脸识别技术分析 1. 非线性数据建模方法 2. 基于3D变形模型的人脸建模 - 案例结合——世 ...

  6. 人脸识别技术大总结1——Face Detection & Alignment

    搞了一年人脸识别,寻思着记录点什么,于是想写这么个系列,介绍人脸识别的四大块:Face detection, alignment, verification and identification(re ...

  7. 基于百度AI人脸识别技术的Demo

    编写demo之前首先浏览官方API:http://ai.baidu.com/docs#/Face-API/top 下面是源码: package com.examsafety.test; import ...

  8. ios OpenCv的配置和人脸识别技术

    作为一个好奇心非常重的人,面对未知的世界都想去一探到底. 于是做了个人脸识别的demo. 眼下国内的关于opencv技术文章非常少.都是互相抄袭.关键是抄个一小部分还不全.时间又是非常久之前的了,和如 ...

  9. paper 97:异质人脸识别进展的资讯

    高新波教授团队异质人脸图像识别研究取得新突破,有望大大降低刑侦过程人力耗费并提高办案效率         近日,西安电子科技大学高新波教授带领的研究团队,在异质人脸图像识别研究领域取得重要进展,其对香 ...

随机推荐

  1. 第 2 章 第 1 题 同位词问题 下问 Multimap实现

    问题分析 输入:一个任意的单词和一个内含多个乱序单词的字典文件 输出:该单词在字典中的所有同位词 约束:允许事先对字典进行预处理 解决思路 上问的程序有个缺点 - 我们必须遍历完整个字典文件才能输出所 ...

  2. Python标准库:内置函数set([iterable])

    本函数是从迭代对象生成集合.集合能够添加或删除元素. 样例: #set() tset = set([1, 2, 3, 3, 4, 5, 6, 6]) print(tset) tset.add(20) ...

  3. Leetcode 001-twosum

    #Given an array of integers, return indices of the two numbers such that they add up to a specific t ...

  4. iOS中从零開始使用protobuf

    让我们一起打开以下这个链接 https://github.com/alexeyxo/protobuf-objc 在github上有protobuf-objc,当中的readme能够教会我们安装prot ...

  5. OTL中文乱码 OTL UTF8

    在用unixODBC连接MySQL的时候字符编码是由odbc支持的,不须要C++编译OTL的时候加上什么编译条件. 假设你的数据库使用的编码是UTF-8,你要从这个数据库读数据.并且还要将结果放到这个 ...

  6. warez世界顶级压缩作品网站

    http://www.pouet.net/ warez世界顶级压缩作品网站

  7. find命令用法

    关于查找 文件查找:     locate非实时查找:根据索引查找     find实时查找:根据文件的各种属性去找到相对应文件     根据文件的各种属性去找到相对应文件 文本搜索:     gre ...

  8. left outer join preserving unmatched rows from the first table

    https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj18922.html INNER JOIN operation Specifies a join ...

  9. ORACLE 表空间扩展

    最近公司在对即将上线的系统做数据迁移和压力测试,于是乎需要和 Oracle 经常的打交道.今天正好碰到了表空间的问题,记录下来以后备用.也是最近才学习到的,原来 Oracle 表空间也是有大小限制的, ...

  10. jquery特效(2)—选项卡

    最近公司有个页面正好用到了选项卡,我就写了一下,感觉还不错,都挺简单的. 下面来看动态效果: 一.主体程序 <!DOCTYPE html> <html> <head> ...