|
libfreenect2 0.4
Open source driver for the Kinect for Windows v2 (K4W2) sensor
|
This path takes you from a source checkout to registered color and depth frames.
Platform guides cover dependency and USB-driver details; this page focuses on the common build, first run, and public C++ API.
Choose the complete setup guide for macOS, Linux, or Windows. All platforms need a Kinect v2 power adapter and a USB 3.0 host connection. Linux users must also install the repository's udev rule before opening the device without root.
Configure and build from the repository root:
Then run the example from the build output. Single-config generators normally place it here:
Multi-config generators such as Visual Studio add a configuration directory, for example build/bin/Release/Protonect.exe. A viewer showing color, IR, and depth confirms that device access, USB transfers, decoding, and the selected depth pipeline all work. If it fails, go directly to Troubleshooting.
The snippets below come from examples/Protonect.cpp, which remains the full working reference.
Include the device and frame-listener APIs. Registration and logging are only needed when your application uses them.
Install a logger before opening a device when you need more or less detail.
libfreenect2 will have an initial global logger created with createConsoleLoggerWithDefaultLevel(). You do not have to explicitly call this if the default is already what you want.
Applications can also implement libfreenect2::Logger. The callback can run from multiple library threads, so custom loggers must synchronize their own state. This example writes messages to a file:
Create a context and enumerate devices before requesting a serial number.
The default pipeline selects the best available implementation for the current build. To require a particular backend, construct a libfreenect2::PacketPipeline explicitly. The example includes the supported selection pattern:
Open by serial number, optionally passing the chosen pipeline.
Attach listeners before starting the device. A libfreenect2::SyncMultiFrameListener groups the requested frame types by arrival; it does not guarantee a timestamp delta or hardware synchronization. Use libfreenect2::TimestampAlignedFrameListener when a bounded device-timestamp threshold is required, and read Frame timing and software pairing for the clock constraints.
Configure depth clipping and filters before start(); see Runtime configuration reference.
Registration uses the factory IR and color camera parameters unless your application explicitly supplies replacements.
Wait for the requested frame set, then retrieve color and depth by frame type.
libfreenect2::Frame documents dimensions, pixel formats, timestamps, and ownership. The registration call below creates undistorted depth and color aligned to the 512×424 depth image:
Release each frame map after the application has finished reading it.
Stop streaming before closing the device and destroying the pipeline.
A device can be paused with libfreenect2::Freenect2Device::stop and restarted with libfreenect2::Freenect2Device::start: