libfreenect2 0.4
Open source driver for the Kinect for Windows v2 (K4W2) sensor
Loading...
Searching...
No Matches

Library context to find and open devices. More...

#include <libfreenect2/libfreenect2.hpp>

Public Member Functions

 Freenect2 (void *usb_context=0)
virtual ~Freenect2 ()
int enumerateDevices ()
 Must be called before doing anything else.
std::string getDeviceSerialNumber (int idx)
std::string getDefaultDeviceSerialNumber ()
bool waitForDevice (const std::string &serial, uint32_t timeout_ms, uint32_t poll_ms=250)
 Wait until a device with serial appears in enumeration.
Freenect2DeviceopenDevice (int idx)
 Open device by index with default pipeline.
Freenect2DeviceopenDevice (int idx, const PacketPipeline *factory)
 Open device by index.
Freenect2DeviceopenDevice (const std::string &serial)
 Open device by serial number with default pipeline.
Freenect2DeviceopenDevice (const std::string &serial, const PacketPipeline *factory)
 Open device by serial number.
Freenect2DeviceopenDefaultDevice ()
 Open the first device with default pipeline.
Freenect2DeviceopenDefaultDevice (const PacketPipeline *factory)
 Open the first device.

Detailed Description

Library context to find and open devices.

You will first find existing devices by calling enumerateDevices().

Then you can openDevice() and control the devices with returned Freenect2Device object.

You may open devices with custom PacketPipeline. After passing a PacketPipeline object to libfreenect2 do not use or free the object, libfreenect2 will take care. If openDevice() fails the PacketPipeline object will get deleted. A new PacketPipeline object has to be created each time a device is opened.

Constructor & Destructor Documentation

◆ Freenect2()

Freenect2 ( void * usb_context = 0)
Parameters
usb_contextIf the libusb context is provided, Freenect2 will use it instead of creating one.

Referenced by openDefaultDevice().

◆ ~Freenect2()

virtual ~Freenect2 ( )
virtual

Member Function Documentation

◆ enumerateDevices()

int enumerateDevices ( )

Must be called before doing anything else.

Returns
Number of devices, 0 if none

◆ getDeviceSerialNumber()

std::string getDeviceSerialNumber ( int idx)
Parameters
idxDevice index
Returns
Device serial number, or empty if the index is invalid.

◆ getDefaultDeviceSerialNumber()

std::string getDefaultDeviceSerialNumber ( )
Returns
Device serial number, or empty if no device exists.

◆ waitForDevice()

bool waitForDevice ( const std::string & serial,
uint32_t timeout_ms,
uint32_t poll_ms = 250 )

Wait until a device with serial appears in enumeration.

This does not revive a closed or disconnected device object. After it returns true, call openDevice(serial) to obtain a fresh object.

Parameters
serialDevice serial number to find.
timeout_msMaximum monotonic wait in milliseconds.
poll_msDelay between enumeration attempts.

◆ openDevice() [1/4]

Freenect2Device * openDevice ( int idx)

Open device by index with default pipeline.

Parameters
idxIndex number. Index numbers are not determinstic during enumeration.
Returns
New device object, or NULL on failure

◆ openDevice() [2/4]

Freenect2Device * openDevice ( int idx,
const PacketPipeline * factory )

Open device by index.

Parameters
idxIndex number. Index numbers are not determinstic during enumeration.
factoryNew PacketPipeline instance. This is always automatically freed.
Returns
New device object, or NULL on failure

◆ openDevice() [3/4]

Freenect2Device * openDevice ( const std::string & serial)

Open device by serial number with default pipeline.

Parameters
serialSerial number
Returns
New device object, or NULL on failure

◆ openDevice() [4/4]

Freenect2Device * openDevice ( const std::string & serial,
const PacketPipeline * factory )

Open device by serial number.

Parameters
serialSerial number
factoryNew PacketPipeline instance. This is always automatically freed.
Returns
New device object, or NULL on failure

◆ openDefaultDevice() [1/2]

Freenect2Device * openDefaultDevice ( )

Open the first device with default pipeline.

Returns
New device object, or NULL on failure

◆ openDefaultDevice() [2/2]

Freenect2Device * openDefaultDevice ( const PacketPipeline * factory)

Open the first device.

Parameters
factoryNew PacketPipeline instance. This is always automatically freed.
Returns
New device object, or NULL on failure

References Freenect2().