From b5646e3f08bf45a27a3db92f5e27568a5448cb03 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期二, 10 十二月 2024 12:34:11 +0800
Subject: [PATCH] 优化串口重连

---
 src/samples/faceApi.ts |  101 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 90 insertions(+), 11 deletions(-)

diff --git a/src/samples/faceApi.ts b/src/samples/faceApi.ts
index 2bcb14a..fa1f959 100644
--- a/src/samples/faceApi.ts
+++ b/src/samples/faceApi.ts
@@ -1,5 +1,6 @@
 // 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';
@@ -8,6 +9,8 @@
 import { confingInfoStore } from '@/stores/StoresConfing'
 import {sendPationCodeApi} from './httpApi'
 import { sockteStore } from '@/stores/sockteInfo';
+import { type } from 'os';
+
 
 // 要识别的人脸库
 const faceDatabase= confingInfoStore().confingInfo.face_database
@@ -41,6 +44,7 @@
  * @param path 图片路径
  */
 const  faceShibie= async(path:any)=>{
+  console.log('文件路径',path)
   const fileStream = fs.createReadStream(path);
   let client=createClient()
   // 通过本地文件
@@ -83,7 +87,70 @@
     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) => {
@@ -96,16 +163,26 @@
   // 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)=>{
@@ -117,7 +194,9 @@
     }
   })
 }
+
 export {
+  yanzhengimg,
   createClient,
   faceShibie,
   base64toFile

--
Gitblit v1.8.0