有理想的咸鱼 Face-api使用记录 2023-06-292023-09-26by 川 face-api是用于人脸识别的js插件,基于tensorflow,下面是一些使用记录,用来做人脸识别,人脸对比,可用于门禁系统,人物识别等地方。git地址:https://github.com/justadudewhohacks/face-api.js/ 1.js端进行两张图片是否是同一个人对比 主要代码$(function(){$(‘#compareBtn’).click( async ()=> {const picElem1 = document.getElementById(‘picture1’);const picElem2 = document.getElementById(‘picture2’);console.log(‘picElem1’)console.log(picElem1)const picture1 = await faceapi.detectAllFaces(picElem1).withFaceLandmarks().withFaceDescriptors();console.log(‘picture1’)console.log(picture1)var landM= await faceapi.detectAllFaces(picElem1).withFaceLandmarks()console.log(‘landM’)console.log(landM)const picture2 = await faceapi.detectAllFaces(picElem2).withFaceLandmarks().withFaceDescriptors();console.log(‘picture2’)const dist = faceapi.euclideanDistance( picture1[0].descriptor,picture2[0].descriptor,);console.log(dist);$(‘#resultRate’).html(dist)// 相似度大于0.4表示不是同一个人if(dist > 0.4){$(‘#result’).html(“不是同一个人”);console.log(‘不是同一个人’)}else {$(‘#result’).html(“是同一个人”);console.log(‘是同一个人’)}})}) 根据生成人脸陆标,计算descriptor,在计算欧氏距离,越小越相近,理论上同一张照片是0,建议在0.4以下认定为同一个人 人脸陆标 2.配合数据库,进行查找,打卡 先在数据里添加信息,再用照片匹配,返还信息 Post Views: 291 分享到