首頁/ 汽車/ 正文

畢設專案-人臉識別考勤簽到系統

畢設專案-人臉識別考勤簽到系統

人臉識別小程式、簽到小程式,藉助百度AI智慧識別功能實現。

需求說明

學生資訊管理,考勤管理,人臉識別處理大概這三個模組。

功能模組:

登入與註冊(兩種身份 老師或學生)

課程釋出(老師可以釋出課程資訊 名稱 地點 選課人數)

課程檢視(學生檢視課程資訊)

人臉錄入(學生登入後有錄入人臉功能)

考勤釋出(老師釋出考勤簽到,課程名稱,開始時間和結束時間)

學生簽到(人臉識別簽到,簽到失敗,遲籤,簽到成功)

考勤記錄檢視(學生ID,課程名稱,簽到狀態)

功能分析

人臉識別呼叫百度智慧雲api就可以。

做人臉識別簽到,其實就是要拿識別的人臉和資料庫裡的人臉對比,相識度大於一定的值,就可以判定成功。

如我們識別的結果是98。295%,所以這裡就可以認定為簽到成功。

畢設專案-人臉識別考勤簽到系統

效果圖

還沒簽到

畢設專案-人臉識別考勤簽到系統

簽到

畢設專案-人臉識別考勤簽到系統

簽到成功

畢設專案-人臉識別考勤簽到系統

接入人臉識別

畢設專案-人臉識別考勤簽到系統

人臉註冊

我們要想實現人臉識別,就需要一開始先在百度的視覺化人臉庫裡註冊人臉,要呼叫的介面如下。

畢設專案-人臉識別考勤簽到系統

畢設專案-人臉識別考勤簽到系統

獲取acess_token

在呼叫這個之前,我們需要先去獲取對應的acess_token,所以接下來我們要做的第一步就是獲取acess_token。我們後面做的所有操作,基本上都要獲取這個。

畢設專案-人臉識別考勤簽到系統

wx。request({ url: ‘https://aip。baidubce。com/oauth/2。0/token’, data: { grant_type: ‘client_credentials’, client_id:, //應用的API Key client_secret: //應用的Secret Key }, header: { ‘Content-Type’: ‘application/json’ // 預設值 }, success: res => { this。setData({ token: res。data。access_token //獲取到token }) console。log(‘獲取到的token’, this。data。token) } })

拍人臉照,註冊人臉到百度人臉庫

我們在拍照以後,獲取到圖片,並透過 wx。getFileSystemManager()。readFile()方法把圖片轉換為base64,因為百度需要這樣格式的資料。

畢設專案-人臉識別考勤簽到系統

var that = this; //拍照 const ctx = wx。createCameraContext() ctx。takePhoto({ quality: ‘high’, success: (res) => { that。setData({ src: res。tempImagePath //獲取圖片 }) //圖片base64編碼 wx。getFileSystemManager()。readFile({ filePath: that。data。src, //選擇圖片返回的相對路徑 encoding: ‘base64’, //編碼格式 success: res => { //成功的回撥 that。setData({ base64: res。data }) //第三步:上傳人臉進行註冊 wx。request({ url: ‘https://aip。baidubce。com/rest/2。0/face/v3/faceset/user/add?access_token=’ + that。data。token, method: ‘POST’, data: { image: that。data。base64, image_type: ‘BASE64’, group_id: ‘users’, //自己建的使用者組id user_id: app。globalData。userInfo。phone, //學號 user_info: app。globalData。userInfo。name //儲存學生姓名 }, header: { ‘Content-Type’: ‘application/json’ // 預設值 }, success(res) { that。setData({ msg: res。data。error_msg }) console。log(“人臉註冊返回結果”, res) //做成功判斷 if (that。data。msg == ‘SUCCESS’) { //微信js字串使用單引號 wx。showToast({ title: ‘註冊成功’, icon: ‘success’, duration: 2000 }) // that。registerFace() } } }), //失敗嘗試 wx。showToast({ title: ‘請重試’, icon: ‘loading’, duration: 500 }) } }) } //拍照成功結束 }) //呼叫相機結束

我們註冊完以後,可以在百度人臉庫裡看到這條資料,可以看到我們建立的users表。

畢設專案-人臉識別考勤簽到系統

檢視人臉庫

畢設專案-人臉識別考勤簽到系統

畢設專案-人臉識別考勤簽到系統

人臉比對

我們上面註冊好人臉以後,接下來就可以使用人臉打卡功能了。 使用之前還是第一步,獲取acess_token。

獲取acess_token

// acess_token獲取 getTokenInfo() { var that = this wx。request({ url: ‘https://aip。baidubce。com/oauth/2。0/token’, data: { grant_type: ‘client_credentials’, client_id: app。globalData。client_id, //應用的API Key client_secret: app。globalData。client_secret //Secret Key }, header: { ‘Content-Type’: ‘application/json’ // 預設值 }, success(res) { that。setData({ token: res。data。access_token //獲取到token }) console。log(that。data。token) } }) },

人臉比對

//拍照並編碼 takePhoto() { let that=this const ctx = wx。createCameraContext() ctx。takePhoto({ quality: ‘high’, success: (res) => { //圖片base64編碼 wx。getFileSystemManager()。readFile({ filePath: res。tempImagePath, //選擇圖片返回的相對路徑 encoding: ‘base64’, //編碼格式 success: res => { //成功的回撥 that。signInFace(res。data) } }) } }) }, //上傳人臉進行 比對 signInFace(base64) { var that = this if (base64 != “”) { wx。request({ url: ‘https://aip。baidubce。com/rest/2。0/face/v3/search?access_token=’ + that。data。token, method: ‘POST’, data: { image: base64, image_type: ‘BASE64’, group_id_list: ‘users’ //自己建的使用者組id }, header: { ‘Content-Type’: ‘application/json’ // 預設值 }, success(res) { console。log(“人臉對比返回結果”, res) if (res。data。error_msg == “match user is not found”) { wx。showModal({ title: ‘簽到失敗’, content: ‘請先註冊人臉才可以人臉使用’, }) } if (res。data。error_msg == “SUCCESS”) { that。setData({ msg: res。data。result。user_list[0]。score, }) // console。log(res) if (that。data。msg > 80) { //相似度大於80 console。log(‘人臉識別成功’) } else { wx。showToast({ title: ‘人臉識別失敗’, }) } } else { wx。showToast({ title: ‘人臉識別失敗’, }) } } }); } if (base64 == “”) { wx。showToast({ title: ‘請重試’, icon: ‘loading’, duration: 500 }) } },

我們執行程式碼以後,會返回一個相識度,我這裡規定相識度80%以上即為同一個人。看日誌可以知道我們的相識度是98。295%,所以這裡就可以認定為簽到成功。

畢設專案-人臉識別考勤簽到系統

相關文章

頂部