0
# Device Management
1
2
Core device discovery, initialization, and control functionality for Microsoft Kinect for Windows v2 devices. This module handles device enumeration, opening connections, configuration, and stream control.
3
4
## Capabilities
5
6
### Freenect2 Context
7
8
Library context for finding and opening Kinect v2 devices. This is the main entry point for device operations.
9
10
```java { .api }
11
/**
12
* Library context to find and open devices.
13
* You will first find existing devices by calling enumerateDevices().
14
* Then you can openDevice() and control devices with returned Freenect2Device object.
15
*/
16
class Freenect2 {
17
/** Constructor using default USB context */
18
Freenect2();
19
20
/** Constructor with custom USB context */
21
Freenect2(Pointer usb_context);
22
23
/** Find available devices - must be called before opening devices */
24
int enumerateDevices();
25
26
/** Get device serial number by index */
27
@StdString BytePointer getDeviceSerialNumber(int idx);
28
29
/** Get default device serial number */
30
@StdString BytePointer getDefaultDeviceSerialNumber();
31
32
/** Open device by index with default pipeline */
33
Freenect2Device openDevice(int idx);
34
35
/** Open device by index with custom pipeline */
36
Freenect2Device openDevice(int idx, @Const PacketPipeline factory);
37
38
/** Open device by serial number with default pipeline */
39
Freenect2Device openDevice(@StdString String serial);
40
41
/** Open device by serial number with custom pipeline */
42
Freenect2Device openDevice(@StdString String serial, @Const PacketPipeline factory);
43
44
/** Open first available device with default pipeline */
45
Freenect2Device openDefaultDevice();
46
47
/** Open first available device with custom pipeline */
48
Freenect2Device openDefaultDevice(@Const PacketPipeline factory);
49
}
50
```
51
52
**Usage Examples:**
53
54
```java
55
import org.bytedeco.libfreenect2.*;
56
import static org.bytedeco.libfreenect2.global.freenect2.*;
57
58
// Initialize library
59
Loader.load(org.bytedeco.libfreenect2.global.freenect2.class);
60
Freenect2 freenect2 = new Freenect2();
61
62
// Find devices
63
int deviceCount = freenect2.enumerateDevices();
64
System.out.println("Found " + deviceCount + " devices");
65
66
// Open default device with CPU pipeline
67
PacketPipeline pipeline = new CpuPacketPipeline();
68
Freenect2Device device = freenect2.openDefaultDevice(pipeline);
69
70
// Or open specific device by serial
71
String serial = freenect2.getDefaultDeviceSerialNumber().getString();
72
device = freenect2.openDevice(serial, pipeline);
73
```
74
75
### Freenect2Device Control
76
77
Device control interface providing configuration and stream management for individual Kinect v2 devices.
78
79
```java { .api }
80
/**
81
* Device control for Kinect v2 devices
82
*/
83
class Freenect2Device {
84
/** Device vendor ID constant */
85
static final int VendorId;
86
87
/** Device product ID constant */
88
static final int ProductId;
89
90
/** Preview device product ID constant */
91
static final int ProductIdPreview;
92
93
/** Get device serial number */
94
@StdString BytePointer getSerialNumber();
95
96
/** Get device firmware version */
97
@StdString BytePointer getFirmwareVersion();
98
99
/** Get current color camera parameters */
100
@ByVal ColorCameraParams getColorCameraParams();
101
102
/** Get current IR camera parameters */
103
@ByVal IrCameraParams getIrCameraParams();
104
105
/** Set color camera parameters (advanced users only) */
106
void setColorCameraParams(@Const @ByRef ColorCameraParams params);
107
108
/** Set IR camera parameters for calibrated accuracy */
109
void setIrCameraParams(@Const @ByRef IrCameraParams params);
110
111
/** Configure depth processing parameters */
112
void setConfiguration(@Const @ByRef Config config);
113
114
/** Set listener for color frames */
115
void setColorFrameListener(FrameListener rgb_frame_listener);
116
117
/** Set listener for IR and depth frames */
118
void setIrAndDepthFrameListener(FrameListener ir_frame_listener);
119
120
/** Start data processing with both RGB and depth streams */
121
@Cast("bool") boolean start();
122
123
/** Start data processing with selected streams */
124
@Cast("bool") boolean startStreams(@Cast("bool") boolean rgb, @Cast("bool") boolean depth);
125
126
/** Stop data processing */
127
@Cast("bool") boolean stop();
128
129
/** Shut down device */
130
@Cast("bool") @Name("close") boolean _close();
131
}
132
```
133
134
**Usage Examples:**
135
136
```java
137
// Device information
138
System.out.println("Serial: " + device.getSerialNumber().getString());
139
System.out.println("Firmware: " + device.getFirmwareVersion().getString());
140
141
// Configure depth processing
142
Freenect2Device.Config config = new Freenect2Device.Config();
143
config.MinDepth(0.5f); // 0.5 meters minimum
144
config.MaxDepth(4.5f); // 4.5 meters maximum
145
config.EnableBilateralFilter(true);
146
config.EnableEdgeAwareFilter(true);
147
device.setConfiguration(config);
148
149
// Start specific streams
150
boolean success = device.startStreams(true, true); // RGB + depth
151
if (!success) {
152
System.err.println("Failed to start streams");
153
}
154
```
155
156
### Device Configuration
157
158
Configuration classes for depth processing and camera calibration parameters.
159
160
```java { .api }
161
/**
162
* Configuration of depth processing
163
*/
164
class Freenect2Device.Config {
165
/** Clip at this minimum distance (meter) */
166
float MinDepth();
167
Config MinDepth(float setter);
168
169
/** Clip at this maximum distance (meter) */
170
float MaxDepth();
171
Config MaxDepth(float setter);
172
173
/** Remove some "flying pixels" */
174
@Cast("bool") boolean EnableBilateralFilter();
175
Config EnableBilateralFilter(@Cast("bool") boolean setter);
176
177
/** Remove pixels on edges because ToF cameras produce noisy edges */
178
@Cast("bool") boolean EnableEdgeAwareFilter();
179
Config EnableEdgeAwareFilter(@Cast("bool") boolean setter);
180
}
181
```
182
183
### Color Camera Parameters
184
185
Color camera calibration parameters with intrinsic and extrinsic values.
186
187
```java { .api }
188
/**
189
* Color camera calibration parameters.
190
* Kinect v2 includes factory preset values for these parameters.
191
* They are used in Registration.
192
*/
193
class Freenect2Device.ColorCameraParams {
194
// Intrinsic parameters
195
/** Focal length x (pixel) */
196
float fx(); ColorCameraParams fx(float setter);
197
/** Focal length y (pixel) */
198
float fy(); ColorCameraParams fy(float setter);
199
/** Principal point x (pixel) */
200
float cx(); ColorCameraParams cx(float setter);
201
/** Principal point y (pixel) */
202
float cy(); ColorCameraParams cy(float setter);
203
204
// Extrinsic parameters for depth-to-color mapping
205
float shift_d(); ColorCameraParams shift_d(float setter);
206
float shift_m(); ColorCameraParams shift_m(float setter);
207
208
// Distortion coefficients
209
float mx_x3y0(); ColorCameraParams mx_x3y0(float setter);
210
float mx_x0y3(); ColorCameraParams mx_x0y3(float setter);
211
float mx_x2y1(); ColorCameraParams mx_x2y1(float setter);
212
float mx_x1y2(); ColorCameraParams mx_x1y2(float setter);
213
float mx_x2y0(); ColorCameraParams mx_x2y0(float setter);
214
float mx_x0y2(); ColorCameraParams mx_x0y2(float setter);
215
float mx_x1y1(); ColorCameraParams mx_x1y1(float setter);
216
float mx_x1y0(); ColorCameraParams mx_x1y0(float setter);
217
float mx_x0y1(); ColorCameraParams mx_x0y1(float setter);
218
float mx_x0y0(); ColorCameraParams mx_x0y0(float setter);
219
220
// Y-axis distortion coefficients
221
float my_x3y0(); ColorCameraParams my_x3y0(float setter);
222
float my_x0y3(); ColorCameraParams my_x0y3(float setter);
223
float my_x2y1(); ColorCameraParams my_x2y1(float setter);
224
float my_x1y2(); ColorCameraParams my_x1y2(float setter);
225
float my_x2y0(); ColorCameraParams my_x2y0(float setter);
226
float my_x0y2(); ColorCameraParams my_x0y2(float setter);
227
float my_x1y1(); ColorCameraParams my_x1y1(float setter);
228
float my_x1y0(); ColorCameraParams my_x1y0(float setter);
229
float my_x0y1(); ColorCameraParams my_x0y1(float setter);
230
float my_x0y0(); ColorCameraParams my_x0y0(float setter);
231
}
232
```
233
234
### IR Camera Parameters
235
236
IR camera intrinsic calibration parameters for depth processing accuracy.
237
238
```java { .api }
239
/**
240
* IR camera intrinsic calibration parameters.
241
* Kinect v2 includes factory preset values for these parameters.
242
* They are used in depth image decoding, and Registration.
243
*/
244
class Freenect2Device.IrCameraParams {
245
/** Focal length x (pixel) */
246
float fx(); IrCameraParams fx(float setter);
247
/** Focal length y (pixel) */
248
float fy(); IrCameraParams fy(float setter);
249
/** Principal point x (pixel) */
250
float cx(); IrCameraParams cx(float setter);
251
/** Principal point y (pixel) */
252
float cy(); IrCameraParams cy(float setter);
253
/** Radial distortion coefficient, 1st-order */
254
float k1(); IrCameraParams k1(float setter);
255
/** Radial distortion coefficient, 2nd-order */
256
float k2(); IrCameraParams k2(float setter);
257
/** Radial distortion coefficient, 3rd-order */
258
float k3(); IrCameraParams k3(float setter);
259
/** Tangential distortion coefficient */
260
float p1(); IrCameraParams p1(float setter);
261
/** Tangential distortion coefficient */
262
float p2(); IrCameraParams p2(float setter);
263
}
264
```
265
266
**Usage Examples:**
267
268
```java
269
// Get factory calibration parameters
270
Freenect2Device.IrCameraParams irParams = device.getIrCameraParams();
271
Freenect2Device.ColorCameraParams colorParams = device.getColorCameraParams();
272
273
System.out.println("IR Camera - fx: " + irParams.fx() + ", fy: " + irParams.fy());
274
System.out.println("Color Camera - fx: " + colorParams.fx() + ", fy: " + colorParams.fy());
275
276
// Use custom calibrated parameters (advanced)
277
irParams.fx(365.456f);
278
irParams.fy(365.456f);
279
device.setIrCameraParams(irParams);
280
```