얼굴 인식 얼굴 값 측정,얼굴 연령 측정,싱크로 율 측정 마이크로 편지 인터페이스

얼굴 평 점 위 챗 인터페이스,위 챗 이미지 주소,curl 요청 face+인터페이스.json 데 이 터 를 분석 하여 얼굴 값 을 계산 합 니 다.사용자 에 게 돌아 갑 니 다.
비 주 얼 매 칭 판,텐 센트 마이크로 학교 에서 체험 하 세 요http://weixiao.qq.com

<?php
/**
 *        、   、        
 * @Created by MOS.Ving.
 * @Author: MOS.Ving
 * @Mail [email protected]
 * @Date: 2016-01-31
 */
 
define("TOKEN", 'weixin'); //  token
 
//FACE++       face++         
define("API_KEY", "api_key=    "); //  face++   api_key
define("API_SECRET", "&api_secret=     ");//  face++   api_secret
define("ATTRIBUTE", "&attribute=glass,pose,gender,age,race,smiling");//          
 
define("DETECT_URL", "http://apicn.faceplusplus.com/v2/detection/detect?");//      (Image)      (Face)           api  
define("LANDMARK_URL", "http://api.faceplusplus.com/detection/landmark?");//      (Face)       ,         ,  25  83     api  
define("COMPARE_URL", "https://apicn.faceplusplus.com/v2/recognition/compare?");//    Face           api  
 
define("TYPE","&type=83p");//83   
 
 
define("MESSAGE_URL", "");//                ,        
 
$wechatObj = new wechatCallbackapiTest();
if($_GET['echostr']){
  $wechatObj->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 = "<item>
           <Title><![CDATA[%s]]></Title>
           <Description><![CDATA[%s]]></Description>
           <PicUrl><![CDATA[%s]]></PicUrl>
           <Url><![CDATA[%s]]></Url>
           </item>";
 
        if($MsgType == "image"){
          $item_str = sprintf($itemTpl, "     ", face($imgUrl), $imgUrl, MESSAGE_URL);
 
          $xmlTpl = "<xml>
           <ToUserName><![CDATA[%s]]></ToUserName>
           <FromUserName><![CDATA[%s]]></FromUserName>
           <CreateTime>%s</CreateTime>
           <MsgType><![CDATA[news]]></MsgType>
           <ArticleCount>%s</ArticleCount>
           <Articles>$item_str</Articles>
           </xml>";
          $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;$i< count($faceArray); $i++){
     
    $resultStr .= "<---- ".($i+1)."  ---->
"; $tempFace = $faceArray[$i]; $faceId = $tempFace['face_id']; $tempAttr = $tempFace['attribute']; // : // value , range $tempAge = $tempAttr['age']; // : // value Male/Female, confidence $tempGenger = $tempAttr['gender']; // : // value Asian/White/Black, confidence $tempRace = $tempAttr['race']; // : //value 0-100 , $tempSmiling = $tempAttr['smiling']; // $sex=$tempGenger['value']; if($sex === "Male") { $resultStr .= " :
"; } else if($sex === "Female") { $resultStr .= " :
"; } // $maxAge = $tempAge['value'] + ($tempAge['range'])/2; $age=ceil($maxAge); $resultStr .= " :".$age." ~
"; // if($tempRace['value'] === "Asian") { $resultStr .= " : ~
"; } else if($tempRace['value'] === "White") { $resultStr .= " : !^ 3^
"; } else if($tempRace['value'] === "Black") { $resultStr .= " : ?!!!
"; } // $smiling = intval($tempSmiling['value']); $smile = round($tempSmiling['value'],3); $resultStr .= " :".$smile."%
"; if($count<3){ // $yanzhi=getYanZhi($faceId,$smiling); $resultStr .= " :".$yanzhi."

"; $resultStr .= "\xe2\x9c\xa8 :
"; switch ($yanzhi){ case $yanzhi>94: $resultStr .=" , !
"; break; case $yanzhi>87: $resultStr .=" , !
"; break; case $yanzhi>82: $resultStr .=" , !
"; break; case $yanzhi>72: $resultStr .=" , !
"; break; case $yanzhi>67: $resultStr .=" , !
"; break; case $yanzhi>62: $resultStr .=" , !
"; break; default: $resultStr .=" , ?
"; } } // , 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 .= "<---- ---->
"; $resultStr .= " :".round($tempEye,3)."%
"; $resultStr .= " :".round($tempEyebrow,3)."%
"; $resultStr .= " :".round($tempMouth,3)."%
"; $resultStr .= " :".round($tempNose,3)."%
"; $resultStr .= "
<---- ---->
:".round($tempResult,3)."%
"; if($tempResult>70){ $resultStr .=" ! !
"; }elseif ($tempResult>50){ $resultStr .=" , ! !
"; }else{ $resultStr .="0.0 。
"; } } // 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; } ?>
시범 도

좋은 웹페이지 즐겨찾기