教你用PHP实现微信小程序人脸识别刷脸登录功能-php教程

资源魔 41 0
教你用PHP完成微信小顺序人脸辨认刷脸登录性能

起首咱们先确认咱们的baidu云人脸库里曾经上传了咱们的集体信息照片;

而后咱们正在后盾写刷脸登岸的接口login咱们要把摄影猎取的照片存储到效劳器;

public function login(){ 
   // 上传文件门路 
   $dir = "./Uploads/temp/"; 
   if(!file_exists($dir)){ 
    mkdir($dir,0777,true); 
   } 
   $upload = new \Think\Upload(); 
   $upload->maxSize = 2048000 ;// 设置附件上传巨细 
   $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 
   $upload->savepath = ''; 
   $upload->autoSub = false; 
   $upload->rootPath = $dir; // 设置附件上传根目次 
   // 上传单个文件 
   $info = $upload->uploadOne($_FILES['file']); 
   if(!$info) {// 上传谬误提醒谬误信息 
     echo json_encode(array('error'=>true,'msg'=>$upload->getError()),JSON_UNESCAPED_UNICODE); 
   }else{// 上传胜利 猎取上传文件信息 
    $file = $dir . $info['savepath'].$info['savename']; 
    $image = base64_encode(file_get_contents($file)); 
    $client = $this->init_face(); 
    $options['liveness_control'] = 'NORMAL'; 
    $options['max_user_num'] = '1'; 
    $ret = $client->search($image,'BASE64','student',$options); 
    // echo json_encode($ret,JSON_UNESCAPED_UNICODE); 
    // exit; 
    if($ret['error_code']==0){ 
     $user = $ret['result']['user_list'][0]; 
     $no = $user['user_id']; 
     $score = $user['score']; 
     if($score>=95){ 
      $data = M('student')->where("no = '{$no}'")->find(); 
      $data['score'] = $score; 
      // $data['name'] = json_decode($data['name'],true); 
      // $data['sex'] = json_decode($data['sex'],true); 
      echo '辨认胜利' . json_encode($data,JSON_UNESCAPED_UNICODE); 
     }else{ 
      echo '辨认失败' . $data['score']; 
     } 
    } 
   } 
  }

而后进行前台设计;

<camera device-position="{{device?'back':'front'}}" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera> 
    <view class="weui-cells__title" >开关</view> 
    <view class="weui-cells weui-cells_after-title"> 
      <view class="weui-cell weui-cell_switch"> 
        <view class="weui-cell__bd">切换摄像头</view> 
        <view class="weui-cell__ft" > 
          <switch bindtap="devicePosition" /> 
        </view> 
      </view> 
    </view> 
<button type="primary" bindtap="takePhoto">刷脸登录</button>

咱们还能够管制相机的先后镜头;

devicePosition() { 
this.setData({ 
 device: !this.data.device, 
}) 
console.log("以后相机摄像头为:", this.data.device ? "后置" : "前置"); 
camera() { 
 let { ctx, type, startRecord } = this.data; }, 
data: { 
 src: null, 
},

正在js外面挪用接口;

takePhoto() { 
   const ctx = wx.createCameraContext() 
   ctx.takePhoto({ 
    quality: 'high', 
    success: (res) => { 
     this.setData({ 
      src: res.tempImagePath 
     }) 
     console.log(res) 
     wx.uploadFile({ 
      url: '', //仅为示例,非实在的接口地点 
      filePath: this.data.src, 
      name: 'file', 
      formData: { 
      }, 
      success: function (res) { 
       // var data = res.data 
       // var json = JSON.parse(data) 
       console.log(res) 
       wx.showModal({ 
        title: "提醒", 
        content: res.data, 
        showCancel: false, 
        confirmText: "确定"
       }) 
      } 
     }) 
    } 
   }) 
  },

刷脸登录就胜利了。

以上就是教你用PHP完成微信小顺序人脸辨认刷脸登录性能的具体内容,更多请存眷资源魔其它相干文章!

标签: php php开发教程 php开发资料 php开发自学

抱歉,评论功能暂时关闭!