forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-pointcloud.js
117 lines (110 loc) · 3.24 KB
/
test-pointcloud.js
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
// Copyright (c) 2017 Intel Corporation. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license
// that can be found in the LICENSE file.
'use strict';
/* global describe, it, before, after */
const assert = require('assert');
let rs2;
try {
rs2 = require('node-librealsense');
} catch (e) {
rs2 = require('../index.js');
}
let ctx;
describe('Pointcloud test', function() {
before(function() {
ctx = new rs2.Context();
const devices = ctx.queryDevices().devices;
assert(devices.length > 0); // Device must be connected
});
after(function() {
rs2.cleanup();
});
it('Testing method destroy', () => {
let pointcloud;
assert.doesNotThrow(() => {
pointcloud= new rs2.PointCloud();
pointcloud.destroy();
});
setTimeout(() => {
assert.equal(pointcloud.pointsFrame, undefined);
assert.equal(pointcloud.cxxPointCloud, undefined);
}, 100);
});
it('Testing method calculate', () => {
let pipeline;
let frameSet;
let pointcloud;
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
});
let endTest = false;
let n = 0;
while (!endTest) {
frameSet = pipeline.waitForFrames();
n++;
console.log(`retring left ...${10 - n} times`);
if (frameSet !== undefined && frameSet.colorFrame !== undefined &&
frameSet.depthFrame !== undefined) {
assert(frameSet.depthFrame instanceof rs2.DepthFrame);
assert(frameSet.colorFrame instanceof rs2.VideoFrame);
let points;
let pointsNull;
assert.doesNotThrow(() => { // jshint ignore:line
points = pointcloud.calculate(frameSet.depthFrame);
});
assert(points instanceof rs2.Points);
assert.throws(() => { // jshint ignore:line
pointsNull = pointcloud.calculate();
});
assert(pointsNull === undefined);
pointcloud.destroy();
endTest = true;
}
if (n >= 10) {
assert(false, 'could not get colorFrame or depthFrame, try to reset camera');
}
}
frameSet.destroy();
pipeline.destroy();
});
it('Testing method mapTo', () => {
let pipeline;
let frameSet;
let pointcloud;
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
});
let endTest = false;
let n = 0;
while (!endTest) {
frameSet = pipeline.waitForFrames();
n++;
console.log(`retring left ...${10 - n} times`);
if (frameSet !== undefined && frameSet.colorFrame !== undefined &&
frameSet.depthFrame !== undefined) {
let rtn;
let rtnNull;
assert.doesNotThrow(() => { // jshint ignore:line
rtn = pointcloud.mapTo(frameSet.colorFrame);
});
assert(rtn === undefined);
assert.throws(() => { // jshint ignore:line
rtnNull = pointcloud.mapTo();
});
assert(rtnNull === undefined);
pointcloud.destroy();
endTest = true;
}
if (n >= 10) {
assert(false, 'could not get colorFrame or depthFrame, try to reset camera');
}
}
frameSet.destroy();
pipeline.destroy();
});
});