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/samples/faceApi.ts | 88 +++++++++++++++++++++++++++++++++++++++-----
1 files changed, 78 insertions(+), 10 deletions(-)
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)=>{
--
Gitblit v1.8.0