From 480c0834c2dc57721022cc9b06d527a3e7cad09b Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 18 七月 2025 13:09:55 +0800
Subject: [PATCH] gx百度sdk适配

---
 src/views/home/index.vue    |    5 +-
 .gitignore                  |    1 
 src/stores/StoresConfing.ts |    4 ++
 package.json                |    1 
 src/samples/faceApi.ts      |   88 +++++++++++++++++++++++++++++++++++++++-----
 5 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index e2d13bc..f6e6e31 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 # Logs
+imgs
 logs
 *.log
 npm-debug.log*
diff --git a/package.json b/package.json
index 09473f4..2c53a99 100644
--- a/package.json
+++ b/package.json
@@ -54,6 +54,7 @@
     "@alicloud/viapi-utils": "^1.0.0",
     "@types/tracking": "^1.1.30",
     "axios": "^0.27.2",
+    "baidu-aip-sdk": "^4.16.16",
     "echarts": "^5.4.3",
     "electron-log": "^4.4.8",
     "electron-store": "^8.0.2",
diff --git a/src/samples/faceApi.ts b/src/samples/faceApi.ts
index 8ec6581..a3089ae 100644
--- a/src/samples/faceApi.ts
+++ b/src/samples/faceApi.ts
@@ -9,7 +9,18 @@
 import { confingInfoStore } from '@/stores/StoresConfing'
 import {sendPationCodeApi} from './httpApi'
 import { sockteStore } from '@/stores/sockteInfo';
-import { type } from 'os';
+
+
+var AipFaceClient = require("baidu-aip-sdk").face;
+
+// 设置APPID/AK/SK
+var APP_ID = "119524671";
+var API_KEY = "53x6fo60pAGACz078FyT2QpY";
+var SECRET_KEY = "r06aXtscuAk2SXHk1FsGM66aUCoGzncU";
+
+// 新建一个对象,建议只保存一个对象调用服务接口
+var clientBaidu = new AipFaceClient(APP_ID, API_KEY, SECRET_KEY);
+
 
 
 // 要识别的人脸库
@@ -40,7 +51,7 @@
   return ossUrl
 }
 /**
- * 
+ * 阿里云人脸识别
  * @param path 图片路径
  */
 const  faceShibie= async(path:any)=>{
@@ -87,6 +98,56 @@
     delImg(path)
   })
 }
+/**
+ * 百度人脸识别
+ * @param path base64 
+ */
+const faceSearchBaidu=async(path:any)=>{
+  const faceScore=confingInfoStore().confingInfo.face_score
+  console.log('文件路径百度识别')
+  console.log(path)
+  try {
+
+    var image = path; // 图片的 base64 数据,图片大小不超过 10M,支持 JPG、PNG、BMP、JPEG 格式
+
+    var imageType = "BASE64";
+    
+    var groupIdList = "test_2018";
+    
+    // 调用人脸搜索
+    clientBaidu.search(image, imageType, groupIdList).then(function(result: any) {
+        console.log(result.error_msg==='SUCCESS','百度人脸识别成功');
+        console.log(result.result.user_list);
+        if(result.error_msg==='SUCCESS'){
+          if(result.result.user_list.length>0){
+            const userList=result.result.user_list
+            const user=userList[0]
+            const entityId=user.user_id
+            const score=user.score
+            console.log(`entityId=`+entityId+','+'score='+score)
+            //设置识别的的两 要大于多少
+            if(entityId!=='unknown'&&score>=faceScore){
+              console.log(entityId,'得到了人脸识别id,存患者code到vuex')
+              sockteStore().setfaceSockte({
+                deviceType: "人脸识别",
+                deviceName: "百度人脸识别",
+                result: entityId,
+                resultTime: new Date().toLocaleString(),
+              })
+            }
+          }
+        }
+        
+    }).catch(function(err: any) {
+        // 如果发生网络错误
+        console.log(err);
+    });
+  } catch (err:any) {
+    console.error('发生错误:', err.message);
+    
+  }
+
+}
 // 验证---逻辑
 const yanzhengimg=async(path:any)=>{
   console.log('文件路径--逻辑',path)
@@ -129,9 +190,13 @@
   }).finally(()=>{
     // console.log('---------------都要执行的')
      // 删除图片
-    // delImg(path)
+    delImg(path)
   })
 }
+/**
+ * 本地人脸识别
+ * @param path 
+ */
 const faceApiCheck=async(path:any)=>{
   const faceScore=confingInfoStore().confingInfo.face_score
   fs.readFile(path, (err, data) => {
@@ -190,11 +255,10 @@
      if (err) {
        console.log(err);
      } else {
-      //  console.log('写入成功!验证阿里', path);
-       // getOssUrl(path)
-       // 验证图片
        // 是否本地识别
        const isLanFace= confingInfoStore().confingInfo.isLanFace
+       // 人脸识别类型
+       const faceType= confingInfoStore().confingInfo.faceType
        if(isLanFace===true){
         console.log('本地识别')
         //本地识别
@@ -202,12 +266,16 @@
        }else{
         //阿里验证外网
         console.log('阿里识别')
-        faceShibie(path)
+        if(faceType==='阿里云'){
+          faceShibie(path)
+        }else if(faceType==='百度'){
+          console.log('百度识别')
+          faceSearchBaidu(base64)
+          //直接删除
+          delImg(path)
        }
-       
-       
      }
-   })
+   } });
 }
 //验证后删除文件图片
 const delImg=(path:string)=>{
diff --git a/src/stores/StoresConfing.ts b/src/stores/StoresConfing.ts
index affed01..6aa200d 100644
--- a/src/stores/StoresConfing.ts
+++ b/src/stores/StoresConfing.ts
@@ -3,6 +3,7 @@
 export const confingInfoStore =defineStore('confingInfo',()=>{
     const confingInfo=ref({
         isLanFace:false,//内网版
+        faceType:"百度",//人脸识别类型  baidu 阿里云
         faceApi:'',
         screenTimeout: 150,
         // 启用人脸识别
@@ -58,6 +59,9 @@
         if(info.isLanFace===undefined){
             confingInfo.value.isLanFace=false
         }
+        if(info.faceType===undefined){
+            confingInfo.value.faceType="阿里云"
+        }
     }
     return {confingInfo,setconfingInfo}
 })
\ No newline at end of file
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index 9b3395a..121c2b3 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -321,9 +321,7 @@
 const getUserMediaFail = ref(false) // 获取用户媒体失败
 let lsDateTime:any=new Date()
 const msg = ref<string>("没识别到人脸...");
-const datetext=computed(()=>{
-  return  formatDate(new Date(),'YYYY-mm-dd  WWW')
-})
+const datetext=ref(formatDate(new Date(),'YYYY-mm-dd  WWW'))
 /**体重发送时候显示在界面的体重 */
 const weightInfoResult=ref() 
 let timer:any=new Date()
@@ -1096,6 +1094,7 @@
       if(clockNum.value===0){
         fuxuan()
       }
+      datetext.value= formatDate(new Date(),'YYYY-mm-dd  WWW')
       date.value=formatDate(new Date(),'YYYY-mm-dd HH:MM')
       if(Number(date.value.substring(11,13))<12){
         timeShidaun.value='上午好!'

--
Gitblit v1.8.0