forked from wouterverweirder/kinect-azure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-stream-rgba32.html
68 lines (60 loc) · 2.66 KB
/
color-stream-rgba32.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Kinect Azure Example</title>
<link rel="stylesheet" href="../assets/vendors/bootstrap-4.3.1-dist/css/bootstrap.css">
<link rel="stylesheet" href="../assets/vendors/bootstrap-4.3.1-dist/css/docs.min.css">
</head>
<body class="container-fluid py-3">
<div class="d-flex align-items-baseline justify-content-between">
<h1 class="bd-title">Color Stream (RGBA32)</h1>
<button onclick="require('electron').remote.getCurrentWebContents().openDevTools()">open dev tools</button>
</div>
<p>
This demo shows the color stream (RGBA32) in an html canvas element. Note that the canvas tag in this demo is resized through css to fit the window. The native image size in this demo is <span id="info">different</span>.
</p>
<canvas id="outputCanvas" class="img-fluid"></canvas>
<script>
{
const KinectAzure = require('kinect-azure');
const kinect = new KinectAzure();
const $info = document.getElementById('info');
const $outputCanvas = document.getElementById('outputCanvas'),
outputCtx = $outputCanvas.getContext('2d');
let outputImageData;
const init = () => {
startKinect();
};
const startKinect = () => {
if(kinect.open()) {
kinect.startCameras({
color_format: KinectAzure.K4A_IMAGE_FORMAT_COLOR_BGRA32,
color_resolution: KinectAzure.K4A_COLOR_RESOLUTION_1080P,
camera_fps: KinectAzure.K4A_FRAMES_PER_SECOND_30,
flip_BGRA_to_RGBA: true
});
kinect.startListening((data) => {
$info.textContent = ` ${data.colorImageFrame.width}x${data.colorImageFrame.height}`;
if (!outputImageData && data.colorImageFrame.width > 0) {
$outputCanvas.width = data.colorImageFrame.width;
$outputCanvas.height = data.colorImageFrame.height;
outputImageData = outputCtx.createImageData($outputCanvas.width, $outputCanvas.height);
}
if (outputImageData) {
renderRGBA32ColorFrame(outputCtx, outputImageData, data.colorImageFrame);
}
});
}
};
const renderRGBA32ColorFrame = (ctx, canvasImageData, imageFrame) => {
canvasImageData.data.set(imageFrame.imageData);
ctx.putImageData(canvasImageData, 0, 0);
};
// expose the kinect instance to the window object in this demo app to allow the parent window to close it between sessions
window.kinect = kinect;
init();
}
</script>
</body>
</html>