-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcolor-control.html
197 lines (180 loc) · 6.65 KB
/
color-control.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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!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 Control</h1>
<button onclick="require('electron').remote.getCurrentWebContents().openDevTools()">open dev tools</button>
</div>
<p>
This demo shows the color control options.
</p>
<canvas id="outputCanvas" class="img-fluid"></canvas>
<div>
<div>
<label>
exposure:
<select name="exposure">
<option value="auto" selected>auto</option>
<option value="500">500</option>
<option value="1250">1250</option>
<option value="2500">2500</option>
<option value="8330">8330</option>
<option value="10000">10000</option>
<option value="16670">16670</option>
<option value="20000">20000</option>
</select>
</label>
</div>
<div>
<label>
brightness:
<input name="brightness" type="number" min="0" max="255" value="128" />
</label>
</div>
<div>
<label>
contrast:
<input name="contrast" type="number" min="0" max="10" value="5" />
</label>
</div>
<div>
<label>
saturation:
<input name="saturation" type="number" min="0" max="50" value="25" />
</label>
</div>
<div>
<label>
sharpness (does not work?):
<input name="sharpness" type="number" min="0" max="255" value="128" />
</label>
</div>
<div>
<label>
whitebalance:
<input name="whitebalance" type="number" min="1000" max="10000" value="5000" />
</label>
</div>
<div>
<label>
backlight compensation:
<input name="backlight" type="checkbox" value="1" checked />
</label>
</div>
<div>
<label>
gain:
<input name="gain" type="number" min="0" max="255" value="128" />
</label>
</div>
<div>
powerline frequency:
<label>
<input type="radio" name="powerline" value="1">
50 Hz
</label>
<label>
<input type="radio" name="powerline" value="2">
60 Hz
</label>
</div>
</div>
<script>
{
const KinectAzure = require('kinect-azure');
const kinect = new KinectAzure();
const $outputCanvas = document.getElementById('outputCanvas'),
outputCtx = $outputCanvas.getContext('2d');
let outputImageData;
const $exposure = document.querySelector('[name=exposure]');
const $brightness = document.querySelector('[name=brightness]');
const $contrast = document.querySelector('[name=contrast]');
const $saturation = document.querySelector('[name=saturation]');
const $sharpness = document.querySelector('[name=sharpness]');
const $whitebalance = document.querySelector('[name=whitebalance]');
const $backlight = document.querySelector('[name=backlight]');
const $gain = document.querySelector('[name=gain]');
const $powerlines = document.querySelectorAll('[name=powerline]');
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
});
kinect.startListening((data) => {
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) {
renderBGRA32ColorFrame(outputCtx, outputImageData, data.colorImageFrame);
}
});
$exposure.addEventListener('change', e => {
if ($exposure.value === "auto") {
kinect.setAutoExposure();
} else {
kinect.setExposure(parseFloat($exposure.value));
}
});
$brightness.addEventListener('change', e => {
kinect.setBrightness(parseFloat($brightness.value));
});
$contrast.addEventListener('change', e => {
kinect.setContrast(parseFloat($contrast.value));
});
$saturation.addEventListener('change', e => {
kinect.setSaturation(parseFloat($saturation.value));
});
$sharpness.addEventListener('change', e => {
kinect.setSharpness(parseFloat($sharpness.value));
});
$whitebalance.addEventListener('change', e => {
kinect.setWhiteBalance(parseFloat($whitebalance.value));
});
$backlight.addEventListener('change', e => {
if ($backlight.checked) {
kinect.setBacklightCompensation(1);
} else {
kinect.setBacklightCompensation(0);
}
});
$gain.addEventListener('change', e => {
kinect.setGain(parseFloat($gain.value));
});
$powerlines.forEach($powerline => {
$powerline.addEventListener('change', e => {
kinect.setPowerlineFrequency(parseFloat($powerline.value));
});
});
}
};
const renderBGRA32ColorFrame = (ctx, canvasImageData, imageFrame) => {
const newPixelData = Buffer.from(imageFrame.imageData);
const pixelArray = canvasImageData.data;
for (let i = 0; i < canvasImageData.data.length; i+=4) {
pixelArray[i] = newPixelData[i+2];
pixelArray[i+1] = newPixelData[i+1];
pixelArray[i+2] = newPixelData[i];
pixelArray[i+3] = 0xff;
}
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>