您好,欢迎访问一九零五行业门户网

人脸识别测颜值、测脸龄、测相似度微信接口,人脸颜值_PHP教程

人脸识别测颜值、测脸龄、测相似度微信接口,人脸颜值人脸评分微信接口,获取微信图片地址,curl请求face++接口。解析json数据,计算颜值。返回用户。
颜值匹配版,请到腾讯微校上体验。http://weixiao.qq.com
valid();}else{ $wechatobj->responsemsg();} class wechatcallbackapitest{ public function valid(){ $echostr = $_get[echostr]; //valid signature , option if($this->checksignature()){ echo $echostr; exit; } } public function responsemsg(){ //get post data, may be due to the different environments $poststr = $globals[http_raw_post_data]; //extract post data if (!empty($poststr)){ /* libxml_disable_entity_loader is to prevent xml external entity injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $fromusername = $postobj->fromusername; $tousername = $postobj->tousername; $keyword = trim($postobj->content); $imgurl = $postobj->picurl; $event = $postobj->event; $eventkey = $postobj->eventkey; $msgtype = $postobj->msgtype; $time = time(); $itemtpl = ; if($msgtype == image){ $item_str = sprintf($itemtpl, 颜值报告单, face($imgurl), $imgurl, message_url); $xmltpl = %s %s $item_str ; $resultstr = sprintf($xmltpl, $fromusername, $tousername, $time, 1); echo $resultstr; } }else { echo ; exit; } } private function checksignature(){ // you must define token by yourself if (!defined(token)){ throw new exception('token is not defined!'); } $signature = $_get[signature]; $timestamp = $_get[timestamp]; $nonce = $_get[nonce]; $token = token; $tmparr = array($token, $timestamp, $nonce); // use sort_string rule sort($tmparr, sort_string); $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }else{ return false; } } } // 调用人脸识别的api返回识别结果function face($imgurl){ // face++ 链接 $jsonstr =curl_get_contents(detect_url.api_key.api_secret.&url=.$imgurl.attribute); $replydic = json_decode($jsonstr,true); $facearray = $replydic['face']; $resultstr = ; for ($i= 0;$i87: $resultstr .=你这么好看,咋不上天呢!\n; break; case $yanzhi>82: $resultstr .=百看不厌,继续加油!\n; break; case $yanzhi>72: $resultstr .=还好,还能看!\n; break; case $yanzhi>67: $resultstr .=哎,只是丑的不明显!\n; break; case $yanzhi>62: $resultstr .=如果有钱,可以去整整!\n; break; default: $resultstr .=让我静静,你家没镜子么?\n; } } //图片中两个人时,计算相似度 if(count($facearray) === 2){ // 获取face_id $tempface1 = $facearray[0]; $tempid1 = $tempface1['face_id']; $tempface2 = $facearray[1]; $tempid2 = $tempface2['face_id']; // face++ 链接 $jsonstr1 = curl_get_contents(compare_url.api_key.api_secret.&face_id2=.$tempid2 .&face_id1=.$tempid1); $replydic1 = json_decode($jsonstr1,true); //取出相似程度 $tempresult = $replydic1['similarity']; $tempsimilarity = $replydic1['component_similarity']; $tempeye = $tempsimilarity['eye']; $tempeyebrow = $tempsimilarity['eyebrow']; $tempmouth = $tempsimilarity['mouth']; $tempnose = $tempsimilarity['nose']; $resultstr .= \n; $resultstr .= 眼睛:.round($tempeye,3).%\n; $resultstr .= 眉毛:.round($tempeyebrow,3).%\n; $resultstr .= 嘴巴:.round($tempmouth,3).%\n; $resultstr .= 鼻子:.round($tempnose,3).%\n; $resultstr .= \n\n两人相似程度:.round($tempresult,3).%\n; if($tempresult>70){ $resultstr .=哇塞!绝对的夫妻相了!\n; }elseif ($tempresult>50){ $resultstr .=哎哟,长得挺像!你们快点在一起吧!\n; }else{ $resultstr .=0.0 长得不太一样哦。\n; } } //如果没有检测到人脸 if($resultstr === ){ $resultstr = 对不起,俺没有识别出来,请换张正脸照试试=.=; } return $resultstr;} //颜值算法function getyanzhi($faceid,$smiling){ $t1=microtime(1); $jsonstr = curl_get_contents(landmark_url.api_key.api_secret.&face_id=.$faceid.type); $t2=microtime(1); if(($t2-$t1)>1.5){ return 75.632; } if ($jsonstr!=false) { $replydic = json_decode($jsonstr,true); $result = $replydic['result']; $landmarkarry = $result[0]; $landmark =$landmarkarry['landmark']; $right_eyebrow_left_corner =$landmark['right_eyebrow_left_corner']; $left_eyebrow_right_corner =$landmark['left_eyebrow_right_corner']; $left_eye_left_corner =$landmark['left_eye_left_corner']; $left_eye_right_corner =$landmark['left_eye_right_corner']; $mouth_left_corner =$landmark['mouth_left_corner']; $mouth_right_corner =$landmark['mouth_right_corner']; $nose_left =$landmark['nose_left']; $nose_right =$landmark['nose_right']; $nose_contour_lower_middle =$landmark['nose_contour_lower_middle']; $right_eye_left_corner =$landmark['right_eye_left_corner']; $right_eye_right_corner =$landmark['right_eye_right_corner']; $contour_left1 =$landmark['contour_left1']; $contour_right1 =$landmark['contour_right1']; $contour_chin =$landmark['contour_chin']; $contour_left6 =$landmark['contour_left6']; $contour_right6 =$landmark['contour_right6']; //计算两眉头间的距离 $c1=distance($left_eyebrow_right_corner['x'],$left_eyebrow_right_corner['y'],$right_eyebrow_left_corner['x'],$right_eyebrow_left_corner['y']); //眉毛之间的中点坐标; $c1_x=($right_eyebrow_left_corner['x']-$left_eyebrow_right_corner['x'])/2+$left_eyebrow_right_corner['x']; $c1_y=($right_eyebrow_left_corner['y']-$left_eyebrow_right_corner['y'])/2+$left_eyebrow_right_corner['y']; //眉毛中点到鼻子最低处的距离 $c2 = distance($nose_contour_lower_middle['x'],$nose_contour_lower_middle['y'],$c1_x,$c1_y); //眼角之间的距离 $c3 = distance($left_eye_right_corner['x'],$left_eye_right_corner['y'],$right_eye_left_corner['x'],$right_eye_left_corner['y']); //鼻子的宽度 $c4 = distance($nose_left['x'],$nose_left['y'],$nose_right['x'],$nose_right['y']); //脸的宽度 $c5 = distance($contour_left1['x'],$contour_left1['y'],$contour_right1['x'],$contour_right1['y']); //下巴到鼻子下方的高度 $c6 = distance($contour_chin['x'],$contour_chin['y'],$nose_contour_lower_middle['x'],$nose_contour_lower_middle['y']); //眼睛的大小 $c7_left = distance($left_eye_left_corner['x'],$left_eye_left_corner['y'],$left_eye_right_corner['x'],$left_eye_right_corner['y']); $c7_right = distance($right_eye_left_corner['x'],$right_eye_left_corner['y'],$right_eye_right_corner['x'],$right_eye_right_corner['y']); //嘴巴的大小 $c8 = distance($mouth_left_corner['x'],$mouth_left_corner['y'],$mouth_right_corner['x'],$mouth_right_corner['y']); //嘴巴处的face大小 $c9 = distance($contour_left6['x'],$contour_left6['y'],$contour_right6['x'],$contour_right6['y']); /* 开始计算步骤 */ $yourmark = 100; $mustm = 0; //眼角距离为脸宽的1/5, $mustm += abs(($c3/$c5)*100 - 25); //鼻子宽度为脸宽的1/5 $mustm += abs(($c4/$c5)*100 - 25); //眼睛的宽度,应为同一水平脸部宽度的!/5 $eyepj = ($c7_left+$c7_right)/2; $mustm += abs($eyepj/$c5*100 - 25); //理想嘴巴宽度应为同一脸部宽度的1/2 $mustm += abs(($c8/$c9)*100 - 50); //下巴到鼻子下方的高度 == 眉毛中点到鼻子最低处的距离 $mustm += abs($c6 - $c2); return round($yourmark-$mustm+$smiling/10,3); }else{ return 60; } } //两点之间的距离function distance($px1,$py1,$px2,$py2){ return sqrt(abs(pow($px2 - $px1,2)) + abs(pow($py2 - $py1,2)));} function curl_get_contents($url) { $ch = curl_init(); curl_setopt( $ch , curlopt_url,$url); curl_setopt( $ch , curlopt_returntransfer,1); curl_setopt( $ch , curlopt_timeout,1); curl_setopt( $ch , curlopt_connecttimeout,1.5); $result = curl_exec($ch); return $result;} ?>
演示图
您可能感兴趣的文章:c#使用微信接口开发微信门户应用php对接微信公众平台消息接口开发流程教程微信公众平台开发接口php sdk完整版微信js接口汇总及使用详解微信api接口大全php使用face++接口开发微信公众平台人脸识别系统的方法微信公众号支付(二)实现统一下单接口
http://www.bkjia.com/phpjc/1119990.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1119990.htmltecharticle人脸识别测颜值、测脸龄、测相似度微信接口,人脸颜值 人脸评分微信接口,获取微信图片地址,curl请求face++接口。解析json数据,计算颜...
其它类似信息

推荐信息