lgq
4 天以前 081f12a52906abe6c2d139fdc144135978681009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
//build: 20250513
//依赖组件:dxDriver,dxStd,dxLogger,dxMap,dxEventBus,dxCommon
import { faceClass } from './libvbar-b-dxface.so'
import dxCommon from './dxCommon.js'
import bus from './dxEventBus.js'
const faceObj = new faceClass();
const face = {}
 
/**
 * 人脸处理初始化
 * @param {object} options 配置参数,大部分可以用默认值
 * @param {string} options.rgbPath 必填,rgb图像采集设备路径,每种设备有差异,比如DW200对应的值是'/dev/video11', M500对应的'/dev/video0'
 * @param {string} options.nirPath 必填,红外图像采集设备路径,每种设备有差异
 * @param {string} options.dbPath 数据库路径,必填
 * @param {number} options.score 特征值对比成功所需最低对比得分 ,非必填(缺省0.6)
 * @param {number} options.dbMax 内存中加载的最大特征列表数量,非必填(缺省5000)
 * @param {string} options.mapPath 标定结果文件路径,非必填
 * @param {string} options.picPath 保存完整人脸照片路径,非必填
 * @param {string} capturerRgbId 必填,rgb取图句柄id
 * @param {string} capturerNirId 必填,nir取图句柄id
 * @returns true/false
 */
face.init = function (options, capturerRgbId, capturerNirId) {
    if (options.rgbPath === undefined || options.rgbPath === null || options.rgbPath.length < 1) {
        throw new Error("dxFace.init: 'rgbPath' parameter should not be null or empty")
    }
    if (options.nirPath === undefined || options.nirPath === null || options.nirPath.length < 1) {
        throw new Error("dxFace.init: 'nirPath' parameter should not be null or empty")
    }
    if (capturerRgbId === undefined || capturerRgbId === null || capturerRgbId.length < 1) {
        throw new Error("dxFace.init: 'capturerRgbId' parameter should not be null or empty")
    }
    if (capturerNirId === undefined || capturerNirId === null || capturerNirId.length < 1) {
        throw new Error("dxFace.init: 'capturerNirId' parameter should not be null or empty")
    }
    capturerRgbId = dxCommon.handleId("capturer", capturerRgbId)
    capturerNirId = dxCommon.handleId("capturer", capturerNirId)
 
    return faceObj.init(options, capturerRgbId, capturerNirId);
}
/**
 * 人脸处理去初始化
 * @returns true/false
 */
face.deinit = function () {
    return faceObj.deinit();
}
 
/**
 * 人脸工作模式
 * @param {number} mode 工作模式,必填( 0 人脸识别模式;1 人脸注册模式)
 * @returns true/false
 */
face.setRecgMode = function (mode) {
    if (mode === undefined || mode === null) {
        throw new Error("dxFace.setRecgMode: 'mode' parameter should not be null or empty")
    }
    return faceObj.setRecgMode(mode)
}
/**
 * 人脸注册
 * @param {string} userId     人员ID,必填
 * @param {string} feature     特征值 base64字符串,必填
 * @returns 0:成功/非0:失败
 */
face.addFaceFeatures = function (userId, feature) {
    if (userId === undefined || userId === null) {
        throw new Error("dxFace.addFaceFeatures: 'userId' parameter should not be null or empty")
    }
    if (feature === undefined || feature === null) {
        throw new Error("dxFace.addFaceFeatures: 'feature' parameter should not be null or empty")
    }
 
    return faceObj.addFaceFeatures(userId, feature)
}
/**
 * 人脸特征值对比
 * @param {string} feature     特征值 base64字符串,必填
 * @param {string} score     比对阈值,非必填,默认0.6
 * @returns string userId
 */
face.faceFeatureCompare = function (feature, score) {
    if (feature === undefined || feature === null) {
        throw new Error("dxFace.faceFeatureCompare: 'feature' parameter should not be null or empty")
    }
    return faceObj.faceFeatureCompare(feature, score)
}
/**
 * 更新配置
 * @param {object} options 注册参数,由注册回调获取,参考face.addFaceFeatures方法
 * @returns true/false
 */
face.faceUpdateConfig = function (options) {
    if (options === null || options === undefined) {
        throw new Error("dxFace.faceUpdateConfig: 'options' parameter should not be null or empty")
    }
    return faceObj.faceUpdateConfig(options)
}
/**
 * 人脸删除
 * @param {string} userId 人员ID,必填
 * @returns true/false
 */
face.deleteFaceFeatures = function (userId) {
    if (userId === null || userId === undefined) {
        throw new Error("dxFace.deleteFaceFeatures: 'userId' parameter should not be null or empty")
    }
    return faceObj.deleteFaceFeatures(userId)
}
/**
 * 根据照片路径和userId注册人脸
 * @param {string} userId     用户id,必填
 * @param {string} picPath    照片路径,必填
 * @returns true/false
 */
face.registerFaceByPicFile = function (userId, picPath) {
    if (userId === undefined || userId === null || userId.length < 1) {
        throw new Error("dxFace.registerFaceByPicFile: 'userId' parameter should not be null or empty")
    }
    if (picPath === undefined || picPath === null || picPath.length < 1) {
        throw new Error("dxFace.registerFaceByPicFile: 'picPath' parameter should not be null or empty")
    }
    return faceObj.registerFaceByPicFile(userId, picPath)
}
/**
 * 人脸线程启用/禁用,功能开关
 * @param {bool} en 启用、禁用,必填
 * @returns true/false
 */
face.faceSetEnable = function (en) {
    if (en === undefined || en === null) {
        throw new Error("dxFace.faceSetEnable: 'en' parameter should not be null or empty")
    }
    return faceObj.detectSetEnable(en ? 0 : -1)
}
 
/**
 * 重置人脸状态
 * @returns 
 */
face.resetFaceStatus = function () {
    return faceObj.resetFaceStatus()
}
 
/**
 * 清空人脸数据
 * @returns true/false
 */
face.faceFeaturesClean = function () {
    return faceObj.faceFeaturesClean()
}
 
/**
 * 获取屏幕亮度
 * @returns number 屏幕亮度
 */
face.getDisplayBacklight = function () {
    return faceObj.getDisplayBacklight()
}
/**
 * 设置屏幕亮度
 * @param {number} light 屏幕亮度,必填
 * @returns true/false
 */
face.setDisplayBacklight = function (light) {
    if (light === undefined || light === null) {
        throw new Error("dxFace.setDisplayBacklight: 'light' parameter should not be null or empty")
    }
    return faceObj.setDisplayBacklight(light)
}
/**
 * 获取屏幕状态
 * @returns number 0-禁用 1-启用
 */
face.getEnableStatus = function () {
    return faceObj.getEnableStatus()
}
/**
 * 设置屏幕状态
 * @param {number} enable 0-禁用 1-启用
 * @returns true/false
 */
face.setEnableStatus = function (enable) {
    if (enable === undefined || enable === null) {
        throw new Error("dxFace.setEnableStatus: 'enable' parameter should not be null or empty")
    }
    return faceObj.setEnableStatus(enable)
}
/**
/**
 * 获取屏幕状态
 * @returns number 0-NORMAL 1-STANDBY
 */
face.getPowerMode = function () {
    return faceObj.getPowerMode()
}
/**
 * 设置屏幕状态
 * @param {number} mode 0-NORMAL 1-STANDBY
 * @returns true/false
 */
face.setPowerMode = function (mode) {
    if (mode === undefined || mode === null) {
        throw new Error("dxFace.setPowerMode: 'mode' parameter should not be null or empty")
    }
    return faceObj.setPowerMode(mode)
}
/**
 * 获取环境光
 * @returns number 环境光亮度
 */
face.getEnvBrightness = function () {
    return faceObj.getEnvBrightness()
}
/**
 * 获取人脸坐标
 * @returns string 人脸坐标JSON
 */
face.getTrackingBox = function () {
    return faceObj.getTrackingBox()
}
/**
 * 查询用户总数
 * @returns number
 */
face.selectCount = function () {
    return faceObj.selectFaceFeatures(1)
}
/**
 * 查询所有userId
 * @returns JSON
 */
face.selectAll = function () {
    return faceObj.selectFaceFeatures(2)
}
/**
 * 判断用户是否存在
 * @returns true/false
 */
face.userExist = function (userId) {
    return faceObj.selectFaceFeatures(3, userId)
}
/**
 * 判断face消息队列是否为空
 * @returns true/false
 */
face.msgIsEmpty = function () {
    return faceObj.msgIsEmpty()
}
/**
 * 从face消息队列中读取数据
 * @returns json
 */
face.msgReceive = function () {
    return JSON.parse(faceObj.msgReceive());
}
 
face.RECEIVE_MSG = '__face__MsgReceive'
 
/**
 * 用于简化face组件微光通信协议的使用,把face封装在这个worker里,使用者只需要订阅eventbus的事件就可以监听face
 */
face.run = function () {
    let workerFile = '/app/code/dxmodules/faceWorker.js'
    bus.newWorker('__face', workerFile)
}
 
/**
 * 如果face单独一个线程,可以直接使用run函数,会自动启动一个线程,
 * 如果想加入到其他已有的线程,可以使用以下封装的函数
 */
face.worker = {
    //在while循环前
    beforeLoop: function (options) {
        // 人脸算法初始化
        face.init(options, options.capturerRgbId, options.capturerNirId)
    },
    //在while循环里
    loop: function () {
        if (!face.msgIsEmpty()) {
            let res = face.msgReceive();
            bus.fire(face.RECEIVE_MSG, res)
        }
    }
}
 
export default face;