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/dxCameraCalibration.js | 136 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/vf205_access/dxmodules/dxCameraCalibration.js b/vf205_access/dxmodules/dxCameraCalibration.js
new file mode 100644
index 0000000..22a6127
--- /dev/null
+++ b/vf205_access/dxmodules/dxCameraCalibration.js
@@ -0,0 +1,136 @@
+//build: 20240528
+//渚濊禆缁勪欢:dxDriver锛宒xLogger锛宒xMap锛宒xCapturer
+import { calibrationClass } from './libvbar-m-dxcapturer_calibration.so'
+import capturer from '../dxmodules/dxCapturer.js'
+import * as os from "os";
+import dxMap from './dxMap.js'
+import log from './dxLogger.js'
+import bus from './dxEventBus.js'
+const calibrationObj = new calibrationClass();
+const map = dxMap.get('default')
+const calibration = {}
+let cnt = 0, startTime = 0;
+
+/**
+ * calibration 鍒濆鍖�
+ * @returns true/false
+ */
+calibration.init = function () {
+ return calibrationObj.init();
+}
+
+/**
+ * calibration 閿�姣�
+ * @returns true/false
+ */
+calibration.deinit = function () {
+ return calibrationObj.deinit();
+}
+
+/**
+ * 璇嗗埆鏍囧畾锛堟嬁鏂规牸绾稿鍑嗗睆骞曚笂鐨勬柟妗嗭級
+ * @param {number} imageRgb image鎸囬拡锛屽繀濉�
+ * @param {number} imageNir image鎸囬拡锛屽繀濉�
+ * @param {number} cnt 鏍囧畾娆℃暟锛屽繀濉紙0锛氱涓�娆℃爣瀹�,1锛氱浜屾鏍囧畾锛�
+ * @returns true/false
+ */
+calibration.calibrationFromImage = function (imageRgb, imageNir, cnt) {
+ return calibrationObj.calibrationFromImage(imageRgb, imageNir, cnt);
+}
+
+/**
+ * 璁$畻骞跺瓨鍌ㄦ爣瀹氱粨鏋�
+ * @param {number} imageNir image鎸囬拡锛屽繀濉�
+ * @param {string} path 瀛樺偍璺緞锛屽繀濉�
+ * @returns true/false
+ */
+calibration.getMap = function (imageRgb, imageNir,cnt, path) {
+ return calibrationObj.getMap(imageRgb, imageNir,cnt, path);
+}
+
+/**
+ * 鑾峰彇缁樺埗鏍囧畾ui妗嗕俊鎭�
+ * @param {number} cnt 鏍囧畾娆℃暟锛屽繀濉紙0锛氱涓�娆℃爣瀹�,1锛氱浜屾鏍囧畾锛�
+ * @param {number} type 妯珫灞忥紝蹇呭~锛�1锛氭í灞忥紝0锛氱珫灞忥級
+ * @returns {x:妯潗鏍�,y:绾靛潗鏍�,w:瀹�,h:楂榼
+ */
+calibration.getBox = function (cnt, type) {
+ let box = calibrationObj.getBox(cnt);
+ let coordinate = {
+ x: type == 1 ? box.x : box.y,
+ y: type == 1 ? box.y : box.x,
+ w: type == 1 ? box.w : box.h,
+ h: type == 1 ? box.h : box.w
+ }
+ return coordinate;
+}
+
+calibration.RECEIVE_MSG = '__calibration__MsgReceive'
+
+/**
+ * 绠�鍖朿ameraCalibration缁勪欢鐨勪娇鐢紝鏃犻渶杞鍘昏幏鍙栨暟鎹紝鏁版嵁浼氶�氳繃eventbus鍙戦�佸嚭鍘�
+ * 鐢变簬璇嗗埆鏍囧畾calibrationFromImage鏄樆濉炵嚎绋嬬殑鏂规硶锛屾墍浠ュ繀椤绘柊寮�涓�涓嚎绋嬫墽琛岋紝鍚﹀垯浼氶樆濉炲叾浠栫嚎绋�
+ * run 鍙細鎵ц涓�娆�
+ * @param {object} options 閰嶇疆鍙傛暟
+ * @param {string} options.capturerRgbId 蹇呭~锛宺gb鍙栧浘鍙ユ焺id
+ * @param {string} options.capturerNirId 蹇呭~锛宯ir鍙栧浘鍙ユ焺id
+ * @param {number} options.timeout 鍗曚綅绉掞紝闈炲繀濉紙缂虹渷20绉掞級锛屾爣瀹氱殑瓒呮椂鏃堕棿锛屽湪姝ゆ湡闂村唴鏈畬鎴愪袱娆℃爣瀹氾紝鍒欐爣瀹氬け璐ョ粨鏉熺嚎绋嬶紝濡傞渶閲嶆柊鏍囧畾锛屽繀椤诲啀娆℃墽琛宺un鏂规硶
+ */
+calibration.run = function (options) {
+ if (options === undefined || options.length === 0) {
+ throw new Error("dxCameraCalibration.run:'options' parameter should not be null or empty")
+ }
+ if (options.capturerRgbId === undefined || options.capturerRgbId === null || options.capturerRgbId.length <= 0) {
+ throw new Error("dxCameraCalibration.run:'capturerRgbId' should not be null or empty")
+ }
+ if (options.capturerNirId === undefined || options.capturerNirId === null || options.capturerNirId.length <= 0) {
+ throw new Error("dxCameraCalibration.run:'capturerNirId' should not be null or empty")
+ }
+ options.timeout = options.timeout ? options.timeout : 20
+ try {
+ if(startTime == null || startTime == 0){
+ startTime = new Date().getTime()
+ }
+ let imageRgb = capturer.readImage(options.capturerRgbId)
+ let imageNir = capturer.readImage(options.capturerNirId)
+ let res = this.calibrationFromImage(imageRgb, imageNir, cnt)
+ if (res) {
+ if (cnt >= 1) {
+ log.info("涓ゆ鏍囧畾鎴愬姛锛岀粨鏉熸爣瀹�")
+ let path = "/etc/.cameraCalibration"
+ if(options.path && options.path.length > 0){
+ path = options.path
+ }
+ this.getMap(imageRgb, imageNir, cnt, path)
+ bus.fire(this.RECEIVE_MSG, "success1")
+ capturer.destroyImage(imageRgb)
+ capturer.destroyImage(imageNir)
+ cnt = 0;
+ startTime = 0;
+ return "success1"
+ }
+ log.info("绗�" + (cnt + 1) + "娆℃爣瀹氭垚鍔�")
+ bus.fire(this.RECEIVE_MSG, "success0")
+ cnt += 1
+ log.info("寮�濮嬭繘琛岀" + (cnt + 1) + "娆℃爣瀹�")
+ return "success0"
+ } else {
+ log.error("绗�" + (cnt + 1) + "娆℃爣瀹氬け璐ワ紝閲嶈瘯涓�")
+ }
+ capturer.destroyImage(imageRgb)
+ capturer.destroyImage(imageNir)
+ let endTime = new Date().getTime()
+ if (endTime - startTime > options.timeout * 1000) {
+ log.error('鏍囧畾瓒呮椂锛岃閲嶆柊鎵ц鏍囧畾')
+ bus.fire(this.RECEIVE_MSG, "timeout")
+ cnt = 0
+ startTime = 0;
+ return "timeout"
+ }
+ return "failed"
+ } catch (error) {
+ log.error(error)
+ }
+}
+
+export default calibration;
\ No newline at end of file
--
Gitblit v1.9.3