| | |
| | | // This file is auto-generated, don't edit it |
| | | import facebody20191230, * as $facebody20191230 from '@alicloud/facebody20191230'; |
| | | import {checkUploadFile} from '@/api/user' |
| | | // 依赖的模块可通过下载工程中的模块依赖文件或右上角的获取 SDK 依赖信息查看 |
| | | import * as $OpenApi from '@alicloud/openapi-client'; |
| | | import Util, * as $Util from '@alicloud/tea-util'; |
| | |
| | | import { confingInfoStore } from '@/stores/StoresConfing' |
| | | import {sendPationCodeApi} from './httpApi' |
| | | import { sockteStore } from '@/stores/sockteInfo'; |
| | | import { type } from 'os'; |
| | | |
| | | |
| | | // 要识别的人脸库 |
| | | const faceDatabase= confingInfoStore().confingInfo.face_database |
| | |
| | | }); |
| | | // 访问的域名 |
| | | config.endpoint = `facebody.cn-shanghai.aliyuncs.com`; |
| | | console.log('人脸识别客户端已启动') |
| | | return new facebody20191230(config); |
| | | } |
| | | // 将文件上传到oss |
| | |
| | | * @param path 图片路径 |
| | | */ |
| | | const faceShibie= async(path:any)=>{ |
| | | console.log('文件路径',path) |
| | | const fileStream = fs.createReadStream(path); |
| | | let client=createClient() |
| | | // 通过本地文件 |
| | | const facedata= confingInfoStore().confingInfo.face_database |
| | | const faceScore=confingInfoStore().confingInfo.face_score |
| | | console.log(facedata,'人脸数据库') |
| | | let searchFaceAdvanceRequest = new $facebody20191230.SearchFaceAdvanceRequest(); |
| | | searchFaceAdvanceRequest.imageUrlObject = fileStream; |
| | | searchFaceAdvanceRequest.dbName = facedata |
| | | searchFaceAdvanceRequest.limit = 2; |
| | | let runtime = new $Util.RuntimeOptions({ }); |
| | | console.log('-----监测图片--') |
| | | client.searchFaceAdvance(searchFaceAdvanceRequest, runtime).then(re=>{ |
| | | // console.log('返回结果') |
| | | // console.log(re.statusCode) |
| | | if(re.statusCode===200){ |
| | | const matchList=re.body.data?.matchList |
| | | // console.log('得到的人脸库') |
| | | console.log(matchList) |
| | | if(matchList?.length>0){ |
| | | const faceItems =matchList[0].faceItems |
| | | if(faceItems?.length===0){ |
| | | console.log('没有找到患者对应的人脸') |
| | | return false |
| | | } |
| | | if(faceItems[0].score>=faceScore){ |
| | | const entityId=faceItems[0].entityId |
| | | console.log(entityId,'得到了人脸识别id,存患者code到vuex') |
| | |
| | | resultTime: '' |
| | | }) |
| | | }else{ |
| | | console.log('那些人脸都不是') |
| | | console.log('没有找到患者对应的人脸') |
| | | } |
| | | } |
| | | |
| | |
| | | delImg(path) |
| | | }) |
| | | } |
| | | // base64z转文件后验证 |
| | | // 验证---逻辑 |
| | | const yanzhengimg=async(path:any)=>{ |
| | | console.log('文件路径--逻辑',path) |
| | | const fileStream = fs.createReadStream(path); |
| | | let client=createClient() |
| | | // 通过本地文件 |
| | | const facedata= confingInfoStore().confingInfo.face_database |
| | | const faceScore=confingInfoStore().confingInfo.face_score |
| | | let searchFaceAdvanceRequest = new $facebody20191230.SearchFaceAdvanceRequest(); |
| | | searchFaceAdvanceRequest.imageUrlObject = fileStream; |
| | | searchFaceAdvanceRequest.dbName = facedata |
| | | searchFaceAdvanceRequest.limit = 2; |
| | | let runtime = new $Util.RuntimeOptions({ }); |
| | | client.searchFaceAdvance(searchFaceAdvanceRequest, runtime).then(re=>{ |
| | | if(re.statusCode===200){ |
| | | const matchList=re.body.data?.matchList |
| | | // console.log('得到的人脸库') |
| | | console.log(matchList) |
| | | if(matchList?.length>0){ |
| | | const faceItems =matchList[0].faceItems |
| | | if(faceItems?.length===0){ |
| | | console.log('没有找到患者对应的人脸') |
| | | return false |
| | | } |
| | | if(faceItems[0].score>=faceScore){ |
| | | const entityId=faceItems[0].entityId |
| | | console.log(entityId,'得到了人脸识别id,存患者code到vuex') |
| | | sockteStore().setfaceSockte({ |
| | | deviceType: "人脸识别", |
| | | deviceName: "人脸识别", |
| | | result: entityId, |
| | | resultTime: '' |
| | | }) |
| | | }else{ |
| | | console.log('没有找到患者对应的人脸') |
| | | } |
| | | } |
| | | |
| | | } |
| | | }).finally(()=>{ |
| | | // console.log('---------------都要执行的') |
| | | // 删除图片 |
| | | // delImg(path) |
| | | }) |
| | | } |
| | | const faceApiCheck=async(path:any)=>{ |
| | | fs.readFile(path, (err, data) => { |
| | | if (err) throw err; |
| | | let blobFile = new File([data], 'name.png', {type:"image/png"}) |
| | | console.log(blobFile) |
| | | const formData = new FormData() // 下面有备注 |
| | | formData.append('file', blobFile) |
| | | checkUploadFile(formData).then(re=>{ |
| | | console.log('-----',re) |
| | | }).finally(()=>{ |
| | | // 删除图片 |
| | | delImg(path) |
| | | }) |
| | | }) |
| | | |
| | | |
| | | |
| | | } |
| | | // base64z转文件后验证 |
| | | const base64toFile = (dataurl:any,filename='file') => { |
| | | if (!fs.existsSync('./imgs')) { |
| | | fs.mkdir('./imgs', (err) => { |
| | |
| | | // new Buffer 操作权限太大,v6.0后使用Buffer.from()创建构造函数 |
| | | const dataBuffer = new Buffer(base64, 'base64'); //把base64码转成buffer对象, |
| | | // return dataBuffer |
| | | fs.writeFile(path, dataBuffer, function(err){//用fs写入文件 |
| | | if(err){ |
| | | console.log(err); |
| | | }else{ |
| | | console.log('写入成功!',path); |
| | | // getOssUrl(path) |
| | | // 验证图片 |
| | | faceShibie(path) |
| | | } |
| | | }) |
| | | fs.writeFile(path, dataBuffer, function (err) { |
| | | if (err) { |
| | | console.log(err); |
| | | } else { |
| | | // console.log('写入成功!验证阿里', path); |
| | | // getOssUrl(path) |
| | | // 验证图片 |
| | | // 是否本地识别 |
| | | const isLanFace= confingInfoStore().confingInfo.isLanFace |
| | | if(isLanFace===true){ |
| | | //本地识别 |
| | | faceApiCheck(path) |
| | | }else{ |
| | | //阿里验证外网 |
| | | faceShibie(path) |
| | | } |
| | | |
| | | |
| | | } |
| | | }) |
| | | } |
| | | //验证后删除文件图片 |
| | | const delImg=(path:string)=>{ |
| | |
| | | } |
| | | }) |
| | | } |
| | | |
| | | export { |
| | | yanzhengimg, |
| | | createClient, |
| | | faceShibie, |
| | | base64toFile |