老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

微信小程序實現人臉識別的方法

這篇文章主要介紹了微信小程序實現人臉識別的方法,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

創新互聯公司專注于企業全網營銷推廣、網站重做改版、清河網站定制設計、自適應品牌網站建設、HTML5建站商城網站制作、集團公司官網建設、外貿網站建設、高端網站制作、響應式網頁設計等建站業務,價格優惠性價比高,為清河等各大城市提供網站開發制作服務。

首先,我們要有開發者工具,今天所說的是后端和前端聯合起來實現的。

在PHP的控制器中寫一個upload方法,代碼如下:

public function upload($id=''){ 
 if(empty($id)){ 
  return false; 
 } 
 
 $no = M("student")->where("id={$id}")->getField('no'); 
 $dir = "./Upload/studentface/"; 
 if(!file_exists($dir)){ 
  mkdir($dir, 0777, true); 
 } 
 $upload = new \Think\Upload();// 實例化上傳類 
 $upload->maxSize = 3145728 ;// 設置附件上傳大小 
 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設置附件上傳類型 
 $upload->rootPath = $dir; // 設置附件上傳根目錄 
 $upload->savePath = ''; // 設置附件上傳(子)目錄 
 $upload->saveName = $no; 
 $upload->replace = true; 
 $upload->autoSub = false; 
 // 上傳文件 
 $info = $upload->uploadOne($_FILES['file']); 
 if(!$info) {// 上傳錯誤提示錯誤信息 
  // return $this->ajaxReturn(array('error'=>true,'msg'=>$upload->getError())); 
  return json_encode(array('error'=>true,'msg'=>$upload->getError()),JSON_UNESCAPED_UNICODE); 
 }else{// 上傳成功 獲取上傳文件信息 
  // return $this->ajaxReturn(array('error'=>false,'msg'=>$info['savepath'].$info['savename'],'id'=>$id)); 
  $file = $dir . $info['savepath'] . $info['savename']; 
  $image = base64_encode(file_get_contents($file)); 
  $this->facevalid($no,$image); 
 
  $m = M('head'); 
  $data = $m->where("no='{$no}'")->find(); 
 
  if($data){ 
  //有數據,則更新 
  $m->where("no='{$no}'")->save(array('base64'=>$image, 'path'=>$file)); 
  }else{ 
  $m->add(array('no'=>$no,'base64'=>$image,'path'=>$file)); 
  } 
 
  return "采集照片成功"; 
 } 
}
public function facevalid($no,$image,$file){ 
 
 $options = array(); 
 
 $options["max_face_num"] = 2; 
 // $options["face_type"] = "LIVE"; 
 
 // $image=file_get_contents($file); 
 // $image=base64_encode($image); 
 // echo $image; 
 $imageType="BASE64"; 
  
 // 帶參數調用人臉檢測 
 $client=$this->init_face(); 
 $ret=$client->detect($image,$imageType,$options); 
 // $arr=$ret; 
 // print_r($ret); 
 // exit; 
 if($ret['error_code']==0){//有人臉 
  $result=$ret['result']; 
  $face_num=$result['face_num']; 
 
  if(1==$face_num){//人臉數量為1 
  $face_probability=$result['face_list'][0]['face_probability']; 
  if(1==$face_probability){//可靠性為1 
   $group=$this->face_group(); 
   
   // echo $group; 
   // exit; 
   $faces=$client->faceGetlist($no,$group); 
   if($faces['error_code']>0){ 
   $client->addUser($image,'BASE64',$group,$no); 
   }else{ 
   $client->updateUser($image,'BASE64',$group,$no); 
   } 
   // echo '人臉檢測完成,并已入庫'; 
   // return true; 
   // $arr = array('error'=>false,'msg'=>'上傳成功'); 
   
  }else{ 
  die('圖片質量'); 
   // die('圖片質量僅為:'.$face_probability.',上傳失敗'); 
  } 
  }else{ 
  die('人臉數量大于1'); 
  // die('人臉數量大于1,失敗'); 
  } 
 }else{ 
  die('沒有人臉'); 
  // die('沒有人臉,失敗'); 
 } 
 }

在前端我們需要在開發者工具里寫js和wxml.

js代碼如下:

const app = getApp() 
Page({ 
 data: { 
 sex: '女', 
 empty:true 
 }, 
 cancel: function () { 
 wx.redirectTo({ 
 url: '../face/face', 
 }) 
 }, 
 
 switch2Change: function (e) { 
 if (e.detail.value) { 
 this.setData({ sex: '男' }) 
 } else { 
 this.setData({ sex: '女' }) 
 } 
 }, 
 formSubmit: function (e) { 
 // console.log(e); 
 wx.request({ 
 url: 'http://*****.top/ppp/server/index.php/home/index/index', 
 data: e.detail.value, 
 method: 'POST', 
 header: { 
 'content-type': 'application/x-www-form-urlencoded' 
 }, 
 success: (res) => { 
 console.log(res.data); 
  
 if (res.data.error) { 
  wx.showToast({ 
  title: res.data.msg, 
  icon: 'none', 
  duration: 2000 
  }) 
 } else { 
  wx.showToast({ 
  title: res.data.msg, 
  icon: 'success', 
  duration: 2000 
  }) 
  
  setTimeout(function () { 
  wx.navigateTo({ 
  url: '../headimg/headimg?id=' + res.data.id, 
  }) 
  }, 2000) 
  
 } 
  
 } 
 
 }) 
 
 } 
  
})

上傳圖片js代碼如下:

const app = getApp() 
function upload(that, id) { 
 if (that.data.files.length == 0) { 
 return; 
 } 
 wx.uploadFile({ 
 url: 'http://****.top/ppp/server/index.php/home/index/upload', //僅為示例,非真實的接口地址 
 filePath: that.data.files[0], 
 name: 'file', 
 formData: { 
 'id': id 
 }, 
 success: function (res) { 
 var data = res.data 
 // var json = JSON.parse(data) 
 console.log(data) 
 wx.showToast({ 
 title: data, 
 icon:'success', 
 duration:2000 
 }) 
 setTimeout(function () { 
 wx.navigateTo({ 
  url: '../index/index', 
 }) 
 }, 2000) 
 } 
 }) 
} 
Page({ 
 chooseImage: function (e) { 
 var that = this; 
 wx.chooseImage({ 
 count: 1, 
 sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,默認二者都有 
 sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機,默認二者都有 
 success: function (res) { 
 console.log(res) 
 // 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標簽的src屬性顯示圖片 
 that.setData({ 
  files: res.tempFilePaths, 
 }); 
 } 
 }) 
 }, 
 //預覽照片 
 previewImage: function () { 
 var current = e.target.dataset.src 
 wx.previewImage({ 
 current: current, 
 urls: this.data.imageList 
 }) 
 }, 
 
 cancel:function(){ 
 wx.redirectTo({ 
 url: '../index/index', 
 }) 
 }, 
 /** 
 * 頁面的初始數據 
 */ 
 data: { 
 files: [], 
 options:null, 
 id:null, 
 }, 
 formSubmit:function(e){ 
 upload(this,this.data.id); 
 }, 
 /** 
 * 生命周期函數--監聽頁面加載 
 */ 
 onLoad: function (options) { 
 console.log(options); 
 this.setData({options:options}) 
 this.setData({ id: options.id }) 
 }, 
 
 /** 
 * 生命周期函數--監聽頁面初次渲染完成 
 */ 
 onReady: function () { 
 
 }, 
 
 /** 
 * 生命周期函數--監聽頁面顯示 
 */ 
 onShow: function () { 
 
 }, 
 
 /** 
 * 生命周期函數--監聽頁面隱藏 
 */ 
 onHide: function () { 
 
 }, 
 
 /** 
 * 生命周期函數--監聽頁面卸載 
 */ 
 onUnload: function () { 
 
 }, 
 
 /** 
 * 頁面相關事件處理函數--監聽用戶下拉動作 
 */ 
 onPullDownRefresh: function () { 
 
 }, 
 
 /** 
 * 頁面上拉觸底事件的處理函數 
 */ 
 onReachBottom: function () { 
 
 }, 
 
 /** 
 * 用戶點擊右上角分享 
 */ 
 onShareAppMessage: function () { 
 
 } 
})

wxml代碼如下:

錄入學生信息 
 
  
  
  
  學號 
  
  
   
  
  
  
  
  姓名 
  
  
   
  
  
  
 性別 
  
  
   
  
  
  
  
  年齡 
  
  
   
  
  
  
  
 注冊 
 返回上級 
  

上傳圖片wxml代碼如下:

 
圖像采集 
{{options.name}} {{options.no}} 
 
 
  
   
   
    
    
    圖片上傳 
    {{files.length}}/1 
    
    
     
     
      
      
      
     
     
     
     
     
    
    
   
   
  
  
  
  確認 
  取消 
  
  

感謝你能夠認真閱讀完這篇文章,希望小編分享的“微信小程序實現人臉識別的方法”這篇文章對大家有幫助,同時也希望大家多多支持創新互聯,關注創新互聯行業資訊頻道,更多相關知識等著你來學習!


本文標題:微信小程序實現人臉識別的方法
文章來源:http://www.xueling.net.cn/article/jpjhhg.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 黑人久久久| 在线免费看黄av | 国产一区在线观看免费 | 91在线在线观看 | 久久精品国产精品青草最新版截图 | 丝袜人妻一区二区三区网站 | 老师穿超短包臀裙办公室爆乳 | 中文字幕免费在线观看 | 在线观看片免费人成视频播放 | 午夜寂寞福利视频 | 久久亚洲av成人无码国产最大 | 99热在线观看免费 | 亚洲国产成人A片乱码 | 欧美国产成人久久精品 | 色一情一乱一伦一区二区三区日本 | 欧美激情精品久久久久久久久久 | 国产一级揄自揄精品视频 | 亚洲精品成人AA片在线播 | 国产日韩视频在线播放 | 欧美精品亚洲 | 一本之道大象高清特色 | 爱情到此为止在线观看 | 欧美黑人巨大xxxxxx | 成全视频在线观看大全腾讯地图 | 91影视大全 | 午夜自产精品一区二区三区 | 欧美一区2区视频在线观看 久久国产亚洲精品 | 巨胸喷奶水www久久久 | 日本九九热在线观看官网 | 欧美日韩成人一区二区三区 | 黑人巨大VS苍井空 | 日韩内射美女人妻一区二区三区 | aa一级片 | 一级片视频在线观看 | 97超碰caoporen公开人人爽 | 欧美日韩精品一区 | 国产精品色网 | 国产又粗又硬又黄视频免费着 | 性吧有你.com | 中国老太婆xxxhd | 久久成人一区二区 |