微信日志开发之人脸识别开发
2015-04-05 22:16
239 查看
这节我们将简单介绍在微信日志中如何实现人脸识别功能
人脸识别我们将会使用Face++提供的api。
需要使用的id以及AppKey请到官网首页注册获取。
(一)实现步骤
1.将用户发送信息获取并提交到服务器
2.服务器端处理信息并返回处理结果
3.将信息返还给用户
(二)实现代码
1.信息提取
在微信日志的主函数中我们有用户输入信息获取的函数,人脸识别的相关信息也可以在其中实现
2.信息提交到服务器并处理
该过程中需要使用到face++的相关api(具体使用方法请参考官网或私信联系)
(三)信息返回给用户
由于我们使用了微信日志作为平台,所以输出函数我们也不用写,直接使用微信日志的相关函数就可以
如果希望自己完成也很简单
通过以上相关函数就可以完成函数的返回。
(四)实现效果
大家可以通过扫描一下二维码体验上述效果,如果对于实现方法有什么不清楚的地方请加微信(dinghinh154)讨论。
人脸识别我们将会使用Face++提供的api。
需要使用的id以及AppKey请到官网首页注册获取。
(一)实现步骤
1.将用户发送信息获取并提交到服务器
2.服务器端处理信息并返回处理结果
3.将信息返还给用户
(二)实现代码
1.信息提取
在微信日志的主函数中我们有用户输入信息获取的函数,人脸识别的相关信息也可以在其中实现
public function __construct() { global $wpdb; if(isset($_GET['echostr'])) $this->valid();//第一次验证 $postStr = (isset($GLOBALS["HTTP_RAW_POST_DATA"]))?$GLOBALS["HTTP_RAW_POST_DATA"]:''; if($_POST["test"]){ $postStr = @$_POST["HTTP_RAW_POST_DATA"]; } //$xml = file_get_contents('php://input'); //$postStr = unicode_encode($postStr); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $RX_TYPE = trim($postObj->MsgType); if($RX_TYPE == 'image')//该处为我们人脸识别函数的添加部分 { $wpdb->postStr = $postStr; $wpdb->postArray = wxlog_xml_to_array($postStr); $this->wxlog_log_id = $this->insert_wxlog_log($wpdb->postArray,$wpdb->postStr); $result = $this->receiveImage($postObj); exit($result); }
2.信息提交到服务器并处理
$faceObj = new FacePlusPlus(); $detect = $faceObj->face_detect($url); $numbers = isset($detect->face)? count($detect->face):0; if($numbers == 1) { } if (($detect->face[0]->attribute->gender->value != $detect->face[1]->attribute->gender->value) && $numbers == 2){ $compare = $faceObj->recognition_compare($detect->face[0]->face_id,$detect->face[1]->face_id); $result = getCoupleComment($compare->component_similarity->eye, $compare->component_similarity->mouth, $compare->component_similarity->nose, $compare->component_similarity->eyebrow, $compare->similarity); return $result; } else{ return "请发送一男一女的图片"; }
该过程中需要使用到face++的相关api(具体使用方法请参考官网或私信联系)
//人脸检测 public function face_detect($urls = null) { return $this->call("detection/detect", array("url"=>$urls)); } //人脸比较 public function recognition_compare($face_id1, $face_id2) { return $this->call("recognition/compare", array("face_id1"=>$face_id1, "face_id2"=>$face_id2)); }
(三)信息返回给用户
由于我们使用了微信日志作为平台,所以输出函数我们也不用写,直接使用微信日志的相关函数就可以
如果希望自己完成也很简单
private function receiveImage($object) { require_once('faceplusplus.php'); $content = getImageInfo((string)$object->PicUrl); $result = $this->transmitText($object, $content); return $result; } private function transmitText($object, $content) { $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content); return $result; }
通过以上相关函数就可以完成函数的返回。
(四)实现效果
大家可以通过扫描一下二维码体验上述效果,如果对于实现方法有什么不清楚的地方请加微信(dinghinh154)讨论。
相关文章推荐
- Windows8开发路线图曝光 "人脸识别"最诱人
- 微信公众平台消息接口开发(20)图片识别之人脸识别
- 微信日志插件开发日记一
- 【Win10 应用开发】人脸识别
- 桃花相册开发笔记(2)——基于人脸识别的相册软件
- 人脸检测和识别开发过程
- 人脸识别 在线音乐,自己开发的一款不太成熟的安卓APP
- Android Camera开发:sdk 14+ 新特新 人脸识别
- PHP实现日志处理类库 - 【微信开发之微电商网站】技术笔记之二
- 微信公共号弹幕开发日志
- 微信公众平台消息接口开发(24)图片识别之人脸识别API
- 微信公众平台消息接口开发(20)图片识别之人脸识别
- VC++开发人脸识别
- iOS/Android开发人脸识别SDK列表
- 微信公众平台消息接口开发(24)图片识别之人脸识别API
- 微信公众平台消息接口开发(20)图片识别之人脸识别
- VC++开发人脸识别
- 微信公众平台消息接口开发(24)图片识别之人脸识别API
- Kinect V2 开发专题(5)坐标映射/人脸识别/语音 - (未完成)
- 微信公众平台开发模式 微信 语音识别 公众平台 消息接口 语音识别