From e491cdb48129752324c4e3764f99bd9203c56dec Mon Sep 17 00:00:00 2001
From: lgq <1015864684@qq.com>
Date: 星期二, 31 三月 2026 09:48:44 +0800
Subject: [PATCH] 1.新增VF205门禁机代码
---
vf205_access/dxmodules/dxFace.js | 287 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 287 insertions(+), 0 deletions(-)
diff --git a/vf205_access/dxmodules/dxFace.js b/vf205_access/dxmodules/dxFace.js
new file mode 100644
index 0000000..a12d723
--- /dev/null
+++ b/vf205_access/dxmodules/dxFace.js
@@ -0,0 +1,287 @@
+//build: 20250513
+//渚濊禆缁勪欢:dxDriver锛宒xStd锛宒xLogger锛宒xMap锛宒xEventBus,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 蹇呭~锛宺gb鍥惧儚閲囬泦璁惧璺緞锛屾瘡绉嶈澶囨湁宸紓锛屾瘮濡侱W200瀵瑰簲鐨勫�兼槸'/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 蹇呭~锛宺gb鍙栧浘鍙ユ焺id
+ * @param {string} capturerNirId 蹇呭~锛宯ir鍙栧浘鍙ユ焺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 娉ㄥ唽鍙傛暟锛岀敱娉ㄥ唽鍥炶皟鑾峰彇锛屽弬鑰僨ace.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)
+}
+/**
+ * 鏍规嵁鐓х墖璺緞鍜寀serId娉ㄥ唽浜鸿劯
+ * @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)
+}
+/**
+ * 鏌ヨ鎵�鏈塽serId
+ * @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()
+}
+/**
+ * 浠巉ace娑堟伅闃熷垪涓鍙栨暟鎹�
+ * @returns json
+ */
+face.msgReceive = function () {
+ return JSON.parse(faceObj.msgReceive());
+}
+
+face.RECEIVE_MSG = '__face__MsgReceive'
+
+/**
+ * 鐢ㄤ簬绠�鍖杅ace缁勪欢寰厜閫氫俊鍗忚鐨勪娇鐢紝鎶奻ace灏佽鍦ㄨ繖涓獁orker閲岋紝浣跨敤鑰呭彧闇�瑕佽闃卐ventbus鐨勪簨浠跺氨鍙互鐩戝惉face
+ */
+face.run = function () {
+ let workerFile = '/app/code/dxmodules/faceWorker.js'
+ bus.newWorker('__face', workerFile)
+}
+
+/**
+ * 濡傛灉face鍗曠嫭涓�涓嚎绋嬶紝鍙互鐩存帴浣跨敤run鍑芥暟锛屼細鑷姩鍚姩涓�涓嚎绋嬶紝
+ * 濡傛灉鎯冲姞鍏ュ埌鍏朵粬宸叉湁鐨勭嚎绋嬶紝鍙互浣跨敤浠ヤ笅灏佽鐨勫嚱鏁�
+ */
+face.worker = {
+ //鍦╳hile寰幆鍓�
+ beforeLoop: function (options) {
+ // 浜鸿劯绠楁硶鍒濆鍖�
+ face.init(options, options.capturerRgbId, options.capturerNirId)
+ },
+ //鍦╳hile寰幆閲�
+ loop: function () {
+ if (!face.msgIsEmpty()) {
+ let res = face.msgReceive();
+ bus.fire(face.RECEIVE_MSG, res)
+ }
+ }
+}
+
+export default face;
--
Gitblit v1.9.3