<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        微信小程序實現人臉識別

        來源:懂視網 責編:小OO 時間:2020-11-27 22:14:10
        文檔

        微信小程序實現人臉識別

        本文為大家分享了微信小程序人臉識別的具體代碼,供大家參考,具體內容如下:首先,我們要有開發者工具,今天所說的是后端和前端聯合起來實現的。在PHP的控制器中寫一個upload方法,代碼如下:
        推薦度:
        導讀本文為大家分享了微信小程序人臉識別的具體代碼,供大家參考,具體內容如下:首先,我們要有開發者工具,今天所說的是后端和前端聯合起來實現的。在PHP的控制器中寫一個upload方法,代碼如下:

        本文為大家分享了微信小程序人臉識別的具體代碼,供大家參考,具體內容如下

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

        在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', 
         }) 
         }, 
         
         switch1Change: 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代碼如下:

        <view class="weui-cells__title text">錄入學生信息</view> 
        <form bindsubmit="formSubmit"> 
         <view class="weui-cells weui-cells_after-title"> 
         <view class="weui-cell weui-cell_input"> 
         <view class="weui-cell__hd"> 
         <view class="weui-label">學號</view> 
         </view> 
         <view class="weui-cell__bd"> 
         <input class="weui-input" placeholder="請輸入學號" value='1635050739' name="no" /> 
         </view> 
         </view> 
         <view class="weui-cell weui-cell_input weui-cell_vcode"> 
         <view class="weui-cell__hd"> 
         <view class="weui-label">姓名</view> 
         </view> 
         <view class="weui-cell__bd"> 
         <input class="weui-input" placeholder="請輸入姓名" value='小蘇' name="name" /> 
         </view> 
         </view> 
         <view class="weui-cell weui-cell_input"> 
         <view class="weui-label">性別</view> 
         <input class="weui-input" name='sex' value='{{sex}}'/> 
         <view class='weui-cell_ft'> 
         <switch checked bindchange='switch1Change'></switch> 
         </view> 
         </view> 
         <view class="weui-cell weui-cell_input weui-cell_vcode"> 
         <view class="weui-cell__hd"> 
         <view class="weui-label">年齡</view> 
         </view> 
         <view class="weui-cell__bd"> 
         <input class="weui-input" placeholder="請輸入年齡" value='20' name="age" /> 
         </view> 
         </view> 
         </view> 
         <view class="weui-btn-area"> 
         <button class="weui-btn" type="primary" bindtap="showTopTips" formType="submit">注冊</button> 
         <button class="weui-btn" type="default" bindtap='cancel'>返回上級</button> 
         </view> 
        </form> 

        上傳圖片wxml代碼如下:

        <view class="page" xmlns:wx="http://www.w3.org/1999/xhtml"> 
        <view class="weui-cells__title text">圖像采集</view> 
        <view class="weui-cells__title text">{{options.name}} {{options.no}}</view> 
        <form bindsubmit="formSubmit"> 
        <view class="page__bd"> 
         <view class="weui-cells"> 
         <view class="weui-cell"> 
         <view class="weui-cell__bd"> 
         <view class="weui-uploader"> 
         <view class="weui-uploader__hd"> 
         <view class="weui-uploader__title">圖片上傳</view> 
         <view class="weui-uploader__info">{{files.length}}/1</view> 
         </view> 
         <view class="weui-uploader__bd"> 
         <view class="weui-uploader__files" id="uploaderFiles"> 
         <block wx:for="{{files}}" wx:key="*this"> 
         <view class="weui-uploader__file" bindtap="previewImage" id="{{item}}"> 
         <image class="weui-uploader__img" src="{{item}}" mode="aspectFill"/> 
         </view> 
         </block> 
         </view> 
         <view class="weui-uploader__input-box"> 
         <view class="weui-uploader__input" bindtap="chooseImage"></view> 
         </view> 
         </view> 
         </view> 
         </view> 
         </view> 
         </view> 
         </view> 
         <view class="weui-btn-area"> 
         <button class="weui-btn" type="primary" form-type="submit">確認</button> 
         <button class="weui-btn" type="default" bindtap='cancel'>取消</button> 
         </view> 
         </form> 
        </view> 

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        微信小程序實現人臉識別

        本文為大家分享了微信小程序人臉識別的具體代碼,供大家參考,具體內容如下:首先,我們要有開發者工具,今天所說的是后端和前端聯合起來實現的。在PHP的控制器中寫一個upload方法,代碼如下:
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 噜噜嘿在线视频免费观看| 久久免费视频99| 日本免费网站在线观看| 亚洲午夜无码久久| 成年美女黄网站色大免费视频| 亚洲a∨无码男人的天堂| 美女被免费喷白浆视频| 亚洲熟女精品中文字幕| 免费无码黄动漫在线观看| 99热在线免费观看| 亚洲av麻豆aⅴ无码电影| 精品亚洲国产成人| 免费看美女被靠到爽的视频| 久久水蜜桃亚洲AV无码精品| 一本色道久久88综合亚洲精品高清| 一级毛片大全免费播放下载| 亚洲无线码在线一区观看| 无码一区二区三区免费| 国产成人精品亚洲日本在线| 国产人妖ts在线观看免费视频| 亚洲欧洲日本精品| 成人免费视频试看120秒| 老司机午夜精品视频在线观看免费 | 亚洲中文字幕AV每天更新| 尤物永久免费AV无码网站| 久久久久免费视频| 亚洲美女在线国产| 白白色免费在线视频| 色视频色露露永久免费观看| 免费无码AV一区二区| 久久亚洲精品无码aⅴ大香| 国产午夜无码精品免费看| 亚洲另类视频在线观看| 免费在线观看a级毛片| 久久久久久久99精品免费观看| 国产99在线|亚洲| 国产精品亚洲A∨天堂不卡| 色婷婷7777免费视频在线观看| 亚洲av午夜精品一区二区三区 | 日韩va亚洲va欧洲va国产| 国产中文字幕在线免费观看|