From 2191b6011fdab3b76344fc2447b8b6aaa972b6c1 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期四, 07 八月 2025 15:48:09 +0800
Subject: [PATCH] 加入完整日志
---
src/samples/faceApi.ts | 110 +++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 90 insertions(+), 20 deletions(-)
diff --git a/src/samples/faceApi.ts b/src/samples/faceApi.ts
index f5755e0..4a0a1aa 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,55 @@
delImg(path)
})
}
+/**
+ * 百度人脸识别
+ * @param path base64
+ */
+const faceSearchBaidu=async(path:any)=>{
+ const faceScore=confingInfoStore().confingInfo.face_score
+ console.log('文件路径百度识别')
+ try {
+
+ var image = path; // 图片的 base64 数据,图片大小不超过 10M,支持 JPG、PNG、BMP、JPEG 格式
+
+ var imageType = "BASE64";
+
+ var groupIdList = confingInfoStore().confingInfo.clientCode; // 人脸库ID列表,多个用逗号分隔,最多支持20个
+
+ // 调用人脸搜索
+ 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 +189,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) => {
@@ -139,18 +203,18 @@
let blobFile = new File([data], 'name.png', {type:"image/png"})
console.log(blobFile)
const formData = new FormData() // 下面有备注
- formData.append('file', blobFile)
+ formData.append('image', blobFile)
checkUploadFile(formData).then(re=>{
console.log('-----',re)
- if(re.code===200&&re?.result?.length>0){
- const result=re.result[0]
- const entityId=result._label
- const distance=result._distance
+ if(re.code===200&&re?.data?.data.result.length>0&&re?.data?.data.result[0]){
+ const result=re?.data?.data.result[0]
+ const entityId=result.user_id
+ const distance=result.score
console.log(`entityId=`+entityId+','+'distance='+distance)
- // 设置识别的的两 要大于多少
- if(entityId!=='unknown'&&distance<=faceScore){
+ //设置识别的的两 要大于多少
+ if(entityId!=='unknown'&&distance>=faceScore){
console.log(entityId,'得到了人脸识别id,存患者code到vuex')
- // console.log(entityId,'得到了人脸识别id,存患者code到vuex')
+ console.log(entityId,'得到了人脸识别id,存患者code到vuex')
sockteStore().setfaceSockte({
type: "人脸识别",
deviceName: "人脸识别",
@@ -159,7 +223,7 @@
state:2,
})
}
-
+ //
}else{
console.log('本地没识别')
}
@@ -190,24 +254,30 @@
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('本地识别')
//本地识别
faceApiCheck(path)
}else{
//阿里验证外网
- console.log('阿里识别')
- faceShibie(path)
+ if(faceType==='阿里云'){
+ console.log('阿里识别')
+ faceShibie(path)
+ }else if(faceType==='百度'){
+ console.log('百度识别')
+ faceSearchBaidu(base64)
+ //直接删除
+ delImg(path)
+ }else{
+ console.log('阿里识别')
+ faceShibie(path)
}
-
-
}
- })
+ } });
}
//验证后删除文件图片
const delImg=(path:string)=>{
--
Gitblit v1.8.0