-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameProcessor.js
More file actions
112 lines (91 loc) · 2.75 KB
/
FrameProcessor.js
File metadata and controls
112 lines (91 loc) · 2.75 KB
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
const rs2 = require('/Users/paul/WebDev/librealsense/wrappers/nodejs/index.js');
const { performance } = require('perf_hooks');
class FrameProcessor {
constructor(width, height, minDistance, maxDistance) {
this.decimationFilter = new rs2.DecimationFilter();
this.spatialFilter = new rs2.SpatialFilter();
this.temporalFilter = new rs2.TemporalFilter();
this.holeFillingFilter = new rs2.HoleFillingFilter();
this.gridWidth = width;
this.gridHeight = height;
this.minDistance = minDistance;
this.maxDistance = maxDistance;
}
decimate(frame) {
frame = this.decimationFilter.process(frame);
frame = this.decimationFilter.process(frame);
frame = this.decimationFilter.process(frame);
return frame;
}
spatialize(frame) {
return this.spatialFilter.process(frame);
}
temporalize(frame) {
return this.temporalFilter.process(frame);
}
fillHoles(frame) {
return this.holeFillingFilter.process(frame);
}
downsample(frame) {
const width = frame.width;
const height = frame.height;
const data = frame.data;
const widthDif = width - this.gridWidth;
const heightDif = height - this.gridHeight;
const widthOffset = widthDif % 2;
const heightOffset = heightDif % 2;
const downsampledFrameData = data.filter((item, index) => {
const onedIndex = index + 1;
// If we are in a row thats not getting used, return
if (
onedIndex <= width * Math.floor(heightDif / 2) ||
onedIndex >
data.length - width * (Math.floor(heightDif / 2) + heightOffset)
)
return false;
// If we are at a column thats not used, return
const column = onedIndex % width || width;
if (
column <= Math.floor(widthDif / 2) ||
column > width - Math.floor(widthDif / 2) - widthOffset
)
return false;
return true;
});
// Mock RS2 Frame object
const downsampledFrame = {
data: downsampledFrameData,
width: this.gridWidth,
height: this.gridHeight
};
return downsampledFrame;
}
mirror(frame) {
const width = frame.width;
const data = frame.data;
let output = new Array();
let temp = new Array();
data.forEach((item, index) => {
temp.push(item);
if ((index + 1) % width === 0) {
temp.reverse();
output = output.concat(temp);
temp = new Array();
}
});
frame.data = output;
return frame;
}
convertToBinary(frame) {
const data = frame.data;
const output = new Array();
data.forEach(item => {
if (item > this.minDistance && item < this.maxDistance) {
output.push(0);
} else output.push(1);
});
frame.data = output;
return frame;
}
}
module.exports = FrameProcessor;