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
//build:20240524
//用于简化cameraCalibration组件的使用,把cameraCalibration封装在这个worker里,使用者只需要订阅eventcenter的事件就可以监听cameraCalibration
import log from './dxLogger.js'
import cameraCalibration from './dxCameraCalibration.js'
import capturer from './dxCapturer.js'
import std from './dxStd.js'
import bus from './dxEventBus.js'
import dxMap from './dxMap.js'
import * as os from "os";
const map = dxMap.get('default')
const options = map.get("__cameraCalibration__run_init")
 
function run() {
    cameraCalibration.init()
    log.info('cameraCalibration start......')
    let startTime = new Date().getTime()
    let cnt = 0
    let timerId = std.setInterval(() => {
        try {
            let imageRgb = capturer.readImage(options.capturerRgbId)
            let imageNir = capturer.readImage(options.capturerNirId)
            let res = cameraCalibration.calibrationFromImage(imageRgb, imageNir, cnt)
            if (res) {
                if (cnt >= 1) {
                    log.info("两次标定成功,结束标定")
                    cameraCalibration.getMap(imageRgb, imageNir, cnt, "/app/path.txt")
                    bus.fire(cameraCalibration.RECEIVE_MSG, "success1")
                    capturer.destroyImage(imageRgb)
                    capturer.destroyImage(imageNir)
                    std.clearInterval(timerId)
                }
                log.info("第" + (cnt + 1) + "次标定成功")
                bus.fire(cameraCalibration.RECEIVE_MSG, "success0")
                cnt += 1
                log.info("开始进行第" + (cnt + 1) + "次标定")
            } 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(cameraCalibration.RECEIVE_MSG, "timeout")
                std.clearInterval(timerId)
            }
        } catch (error) {
            log.error(error, error.stack)
        }
    }, 10)
}
 
try {
    run()
} catch (error) {
    log.error(error, error.stack)
}