


WeChat public platform messaging interface develops image recognition and face recognition
Mar 01, 2017 am 09:35 AM1. Foreword
The first few small applications seem to be weak, and the response is lukewarm. It seems that everyone is not interested. Today I will introduce a more eye-catching one for you: the WeChat public platform Face recognition.
I saw a report on the Internet some time ago that Wei Xiaoyong, associate professor and director of the Computer Science Department of Sichuan University, developed an image-based classroom attendance system. Face recognition is used to 'swipe your face' during class roll call. See the picture below.
During roll call, you only need to take photos of the students in the classroom from multiple angles, then upload the photos to the server, automatically stitch them into a whole picture, and the system will then compare the photos The student avatars in the app are automatically numbered and identified, and the student's personal information appears at the end, with two options: "It'sme (it's me)" and "notme (not me)". In this way, you can immediately know who is in class and who is skipping class
What’s even more amazing is the statistical significance of this thing: it can even analyze students’ interpersonal relationships and even personality interests. Where do you like to sit in class and who do you like to sit next to? After getting the raw data, after a period of time, you can analyze who is in love with whom, and who is with whom after breaking up. Who always likes to sit alone in the corner (autism), a certain boy and a certain boy have been sitting together every time for half a year (gay friends???), and instantly feel that this thing gives people unlimited space for imagination big. . . . . .
Let’s get down to business:
First, let’s take a look at what face recognition is, and look at the definition of Baidu Encyclopedia: Face recognition specifically refers to the use of analysis and comparison of face vision Computer technology for identification using characteristic information. Face recognition is a popular field of computer technology research. It can detect the light and dark of the face, automatically adjust the dynamic exposure compensation, track and detect the face, and automatically adjust the image magnification; it belongs to biometric identification technology and is a tool for biological identification. Generally refers to the biological characteristics of a person) to distinguish individual organisms.
The technical process of face recognition (from Baidu Encyclopedia)
It is generally divided into three steps:
(1) First create a face image file. That is, a camera is used to collect facial image files of the faces of unit personnel or take their photos to form facial image files, and these facial image files are generated into facial print (Faceprint) codes and stored.
(2) Get the current human face image. That is, use a camera to capture the face image of the current person entering or exiting, or take a photo to input, and generate a facial pattern code from the current face image file.
(3) Compare the current facial pattern code with the archive inventory. That is, the facial pattern code of the current facial image is retrieved and compared with the facial pattern code in the archive inventory. The above-mentioned "facial pattern encoding" method works based on the essential characteristics and beginnings of the human face. This facial pattern encoding is robust to changes in light, skin tone, facial hair, hairstyle, eyewear, expression and posture, allowing it to accurately identify an individual among millions of others. The face recognition process can be completed automatically, continuously, and in real time using ordinary image processing equipment.
2. Face recognition on the WeChat public platform
1. Obtain pictures
First of all, we must obtain the pictures sent by the users, WeChat public platform Supports receiving pictures. A picture sent by the
user is as follows:
The format of the picture message is as follows:
<xml> <ToUserName><![CDATA[gh_13d1a3a7x46a]]></ToUserName> <FromUserName><![CDATA[oKaHDjt60aAyPvQmUX3ddyix_zG8]]></FromUserName> <CreateTime>1357543196</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[http://ipnx.cn/]]></PicUrl> <MsgId>5830603629728080261</MsgId></xml>
ToUserName WeChat ID of the message receiver, usually the public platform account WeChat ID
FromUserName WeChat ID of the message sender
CreateTime Message creation time
MsgType Message type; picture message Provide the face recognition interface for image
PicUrl image link address
MsgId message ID number
2. Interface
Face++,
Detect the positions of all faces (Face) in a given image (Image) and the corresponding facial attribute interface address is as follows:
http://apicn.faceplusplus.com/v2/detection/detect
Parameter | Is it required | Meaning |
api_key | Required | App’s Face++ API Key |
api_secret | Required | APP’s Face++ API Secret |
url or img[POST] | must | The URL of the image to be detected or pass For binary data uploaded by POST method, the original image size needs to be less than 3M |
mode | optional | 檢測模式可以是normal(默認) 或者 oneface 。在oneface模式中,檢測器僅找出圖片中最大的一張臉。 |
attribute | 可選 | 可以是none或者由逗號分割的屬性列表。默認為gender, age, race, smiling。目前支持的屬性包括:gender, age, race, smiling, glass, pose |
tag | 可選 | 可以為圖片中檢測出的每一張Face指定一個不包含^@,&=*'"等非法字符且不超過255字節(jié)的字符串作為tag,tag信息可以通過 /info/get_face 查詢 |
async | 可選 | 如果置為true,該API將會以異步方式被調(diào)用;也就是立即返回一個session id,稍后可通過/info/get_session查詢結(jié)果。默認值為false。 |
返回如下
{ "face": [ { "attribute": { "age": { "range": 5, "value": 17 }, "gender": { "confidence": 99.9781, "value": "Female" }, "glass": { "confidence": 99.9815, "value": "None" }, "pose": { "pitch_angle": { "value": 0.000019753399999999996 }, "roll_angle": { "value": 1.75177 }, "yaw_angle": { "value": 4 } }, "race": { "confidence": 99.471, "value": "Asian" }, "smiling": { "value": 87.1365 } }, "face_id": "c772b4b66c00d46b15344eff74b56e48" } ], "img_height": 293, "img_id": "3005132383841edd08c9b500fb1fe2c4", "img_width": 440, "session_id": "4e64c73fec19442cbefde3cf9bd6b53d", "url": "" }
參數(shù):
gender | object | 包含性別分析結(jié)果,value的值為Male/Female, confidence表示置信度 |
age | object | 包含年齡分析結(jié)果,value的值為一個非負整數(shù)表示估計的年齡, range表示估計年齡的正負區(qū)間 |
race | object | 包含人種分析結(jié)果,value的值為Asian/White/Black, confidence表示置信度 |
smiling | object | 包含微笑程度分析結(jié)果,value的值為0-100的實數(shù),越大表示微笑程度越高 |
實現(xiàn)方法
取結(jié)果參數(shù)中的gender,age,race,smiling等參數(shù) ,如
"attribute": { "age": { "range": 5, "value": 17 }, "gender": { "confidence": 99.9781, "value": "Female" }, "glass": { "confidence": 99.9815, "value": "None" }, "pose": { "pitch_angle": { "value": 0.000019753399999999996 }, "roll_angle": { "value": 1.75177 }, "yaw_angle": { "value": 4 } }, "race": { "confidence": 99.471, "value": "Asian" }, "smiling": { "value": 87.1365 }
上述結(jié)果中,
年齡age為17,誤差在5歲 性別為female,表示女,置信度為99% 種族為亞洲Asian, 微笑度 87%
和圖片比較一下,還是比較一致的
3. 程序?qū)崿F(xiàn)
SDK如下:
"attribute": { "age": { "range": 5, "value": 17 }, "gender": { "confidence": 99.9781, "value": "Female" }, "glass": { "confidence": 99.9815, "value": "None" }, "pose": { "pitch_angle": { "value": 0.000019753399999999996 }, "roll_angle": { "value": 1.75177 }, "yaw_angle": { "value": 4 } }, "race": { "confidence": 99.471, "value": "Asian" }, "smiling": { "value": 87.1365 }
調(diào)用方式如下:
<?PHP /** * Face++ PHP SDK * author: Tianye * since: 2013-12-11 **/ class Facepp{ ###################################################### ### If you choose Amazon(US) server,please use the ### ### http://apius.faceplusplus.com/v2 ### ### or ### ### https://apius.faceplusplus.com/v2 ### ###################################################### var $server = 'http://apicn.faceplusplus.com/v2'; #var $server = 'https://apicn.faceplusplus.com/v2'; #var $server = 'http://apius.faceplusplus.com/v2'; #var $server = 'https://apius.faceplusplus.com/v2'; ############################################# ### set your api key and api secret here. ### ############################################# var $api_key = '{your API KEY}'; var $api_secret = '{your API SECRET}'; public function __construct($api_key=NULL, $api_secret=NULL, $server=NULL){ if($api_key){ $this->api_key = $api_key; } if($api_secret){ $this->api_secret = $api_secret; } if($server){ $this->server = $server; } } /** * @param $method : The Face++ API * @param $params : Request Parameters * @return : Array {'http_code':'Http Status Code', 'request_url':'Http Request URL','body':' JSON Response'} **/ public function execute($method,$params){ if(empty($params)){ $params=array(); } $params['api_key'] = $this->api_key; $params['api_secret'] = $this->api_secret; return $this->request("{$this->server}{$method}",$params); } private function request($request_url , $request_body){ $useragent = 'Faceplusplus PHP SDK/1.0'; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $request_url); curl_setopt($curl_handle, CURLOPT_FILETIME, TRUE); curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, FALSE); curl_setopt($curl_handle, CURLOPT_CLOSEPOLICY, CURLCLOSEPOLICY_LEAST_RECENTLY_USED); curl_setopt($curl_handle, CURLOPT_MAXREDIRS, 5); curl_setopt($curl_handle, CURLOPT_HEADER, FALSE); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5184000); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 120); curl_setopt($curl_handle, CURLOPT_NOSIGNAL, TRUE); curl_setopt($curl_handle, CURLOPT_REFERER, $request_url); curl_setopt($curl_handle, CURLOPT_USERAGENT, $useragent); if (extension_loaded('zlib')){ curl_setopt($curl_handle, CURLOPT_ENCODING, ''); } curl_setopt($curl_handle, CURLOPT_POST, TRUE); if(array_key_exists('img',$request_body)){ $request_body['img'] = '@'.$request_body['img']; }else{ $request_body=http_build_query($request_body); } curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $request_body); $response_text = curl_exec($curl_handle); $reponse_header = curl_getinfo($curl_handle); curl_close($curl_handle); return array('http_code'=>$reponse_header['http_code'],'request_url'=>$request_url,'body'=>$response_text); } }
在微信中再將結(jié)果整理成文本消息就可以了。
?
4. 效果展示
下面是實際使用結(jié)果:
漂亮/帥氣指數(shù)鑒定技術(shù)
近親及親子鑒定技術(shù)
男人味/女人味鑒定技術(shù)
更多WeChat public platform messaging interface develops image recognition and face recognition相關(guān)文章請關(guān)注PHP中文網(wǎng)!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)