-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract-frame-info.ts
181 lines (171 loc) · 4.62 KB
/
extract-frame-info.ts
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
import {AnalysisResult as WasmAnalysisResult} from "./smooth/smooth";
export interface Point {
x: number;
y: number;
}
export interface Circle {
center: Point;
radius: number;
}
export interface ThermalReference {
geom: Circle;
val: number;
temp: number;
}
export enum ScreeningState {
INIT = "INIT",
WARMING_UP = "WARMING_UP",
READY = "READY", // no face
HEAD_LOCK = "HEAD_LOCK",
TOO_FAR = "TOO_FAR",
LARGE_BODY = "LARGE_BODY",
FACE_LOCK = "FACE_LOCK", // has face
FRONTAL_LOCK = "FRONTAL_LOCK", // Face is front-on
STABLE_LOCK = "STABLE_LOCK", // Face has not changed in size or position for a couple of frames.
MEASURED = "MEASURED", // Temperature snapshot taken, waiting for the person to leave the frame.
MISSING_THERMAL_REF = "MISSING_REF"
}
export interface FaceInfo {
halfwayRatio: number;
headLock: number;
isValid: boolean;
samplePoint: Point;
sampleValue: number;
sampleTemp: number;
head: {
topLeft: Point;
topRight: Point;
bottomLeft: Point;
bottomRight: Point;
};
}
export interface AnalysisResult {
motionSum: number;
motionThresholdSum: number;
thresholdSum: number;
frameBottomSum: number;
heatStats: {
min: number;
max: number;
threshold: number;
};
face: FaceInfo;
nextState: ScreeningState;
hasBody: boolean;
thermalRef: ThermalReference;
}
function getScreeningState(state: number): ScreeningState {
let screeningState = ScreeningState.INIT;
switch (state) {
case 0:
screeningState = ScreeningState.WARMING_UP;
break;
case 1:
screeningState = ScreeningState.READY;
break;
case 2:
screeningState = ScreeningState.HEAD_LOCK;
break;
case 3:
screeningState = ScreeningState.TOO_FAR;
break;
case 4:
screeningState = ScreeningState.LARGE_BODY;
break;
case 5:
screeningState = ScreeningState.FACE_LOCK;
break;
case 6:
screeningState = ScreeningState.FRONTAL_LOCK;
break;
case 7:
screeningState = ScreeningState.STABLE_LOCK;
break;
case 8:
screeningState = ScreeningState.MEASURED;
break;
case 9:
screeningState = ScreeningState.MISSING_THERMAL_REF;
break;
}
return screeningState;
}
export function extractFrameInfo(analysisResult: WasmAnalysisResult): AnalysisResult {
const f = analysisResult.face;
const h = f.head;
const tL = h.top_left;
const tR = h.top_right;
const bL = h.bottom_left;
const bR = h.bottom_right;
const sP = f.sample_point;
const hS = analysisResult.heat_stats;
const ref = analysisResult.thermal_ref;
const geom = ref.geom;
const cP = geom.center;
const copiedAnalysisResult: AnalysisResult = {
face: {
headLock: f.head_lock,
head: {
topLeft: {
x: tL.x,
y: tL.y
},
topRight: {
x: tR.x,
y: tR.y
},
bottomLeft: {
x: bL.x,
y: bL.y
},
bottomRight: {
x: bR.x,
y: bR.y
}
},
samplePoint: {
x: sP.x,
y: sP.y
},
sampleTemp: f.sample_temp,
sampleValue: f.sample_value,
halfwayRatio: f.halfway_ratio,
isValid: f.is_valid
},
frameBottomSum: analysisResult.frame_bottom_sum,
motionSum: analysisResult.motion_sum,
heatStats: {
threshold: hS.threshold,
min: hS.min,
max: hS.max
},
motionThresholdSum: analysisResult.motion_threshold_sum,
thresholdSum: analysisResult.threshold_sum,
nextState: getScreeningState(analysisResult.next_state),
hasBody: analysisResult.has_body,
thermalRef: {
geom: {
center: {
x: cP.x,
y: cP.y
},
radius: geom.radius
},
val: ref.val,
temp: ref.temp
}
};
f.free();
h.free();
tL.free();
tR.free();
bL.free();
bR.free();
sP.free();
hS.free();
cP.free();
geom.free();
ref.free();
analysisResult.free();
return copiedAnalysisResult;
}