Files
kinect/docs/setup-linux.md
kinect-bot 39876fa97b
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python root tests (pytest, no tracker deps) (push) Canceled after 0s
ci / Python tracker (pytest, tracker/.venv) (push) Canceled after 0s
docs(setup): README + linux/windows setup + calibration/troubleshooting + packaging (wave 11; todo 18 done)
2026-11-25 06:10:54 -05:00

9.6 KiB

Linux setup guide

This is the exact, reproducible Linux pipeline: build the OS-agnostic core, stand up the Python tracker, provision a user-space OpenNI2 runtime, build the OpenNI2 "SynthKinect" driver, and watch moving synthetic depth flow through a real, independent OpenNI2 consumer.

Following this from a clean checkout reaches the plan's todo-10 result: a sequence of moving, in-band, articulated depth frames read out of a real OpenNI2 stack driven by the live webcam/MediaPipe tracker. That is the verified Linux surface (plan IS-6, IS-7 depth half).

What is verified vs blocked on Linux

Path Status
Core build + unit tests (libnui_core, CTest) verified
Python tracker: MediaPipe pose + mask through the frozen IPC contract verified (against a recorded video; live --source 0 needs a real camera)
OpenNI2 "SynthKinect" driver + independent OpenNI2 depth consumer verified: moving articulated depth read through a real OpenNI2 stack
usbip/vhci device-attach (the attach/linux lane) [~] blocked here: no usbip userspace, no loaded vhci-hcd controller on this WSL2 kernel. Code compiles and unit-tests; live USB attach needs a native-Linux host or a kernel with a matching linux-tools/usbip package. See attach/linux/README.md.
Skeleton tracking on Linux (NiTE2) out of scope: NiTE2 is non-redistributable. Supply it yourself to get a skeleton; depth/enumeration work without it.

The verified route below is the OpenNI2 driver (fallback) path, which proves depth and enumeration end to end without the USB-attach blocker. It is the Linux surface the e2e harness exercises.

0. Prerequisites

A Linux (or WSL2) box with g++, python3, curl, and git. No root is required for the verified path; every dependency below installs into your home directory.

cmake is not assumed present. Install it into the per-user site (PEP-668 externally-managed systems need the --break-system-packages flag, which only touches your user site):

pip install --user --break-system-packages cmake
export PATH="$HOME/.local/bin:$PATH"   # put this in your shell rc
cmake --version                        # expect 4.x

1. Build the OS-agnostic core and run its tests

cd /path/to/kinect
export PATH="$HOME/.local/bin:$PATH"
cmake -S . -B build/linux
cmake --build build/linux
ctest --test-dir build/linux --output-on-failure

GoogleTest is fetched once via CMake FetchContent at configure time (network needed once; then cached under build/linux/_deps). This builds libnui_core (contract, mapping, synth, protocol, calibration) and runs the C++ unit suite plus the Python/C contract interop check.

2. Stand up the Python tracker environment

System Python here is 3.14, which has no MediaPipe wheel and a broken ensurepip. The working route is user-space uv with a pinned Python 3.12:

pip install --user --break-system-packages uv
export PATH="$HOME/.local/bin:$PATH"
uv python install 3.12
uv venv --python 3.12 tracker/.venv
uv pip install --python tracker/.venv numpy pytest opencv-python-headless mediapipe

Known-good versions installed this way: Python 3.12.16, numpy 2.5.5, opencv-python-headless 5.1.0, mediapipe 1.2.3.

2a. MediaPipe model bundles

MediaPipe 1.x ships only the Tasks API and loads a .task bundle. Fetch the tiers into tracker/models/ (git-ignored):

base="https://storage.googleapis.com/mediapipe-models/pose_landmarker"
for t in lite full heavy; do
  curl -fsSL -o tracker/models/pose_landmarker_$t.task \
    "$base/pose_landmarker_$t/float16/latest/pose_landmarker_$t.task"
done

full is the selected tier (>=25 fps on CPU at the test resolution; heavy drops below).

2b. User-space libGLESv2 workaround

MediaPipe 1.2.3's native bindings need libGLESv2.so.2. If it is absent and you cannot apt install libgles2 (no sudo), stage it into your home directory from the package payload:

cd /tmp && apt-get download libgles2 && dpkg-deb -x libgles2_*.deb ext
mkdir -p ~/.cache/kinect/gllibs && cp -a ext/usr/lib/*/libGLESv2.so.2* ~/.cache/kinect/gllibs/

Then prepend it to the loader path whenever you run the tracker:

export LD_LIBRARY_PATH="$HOME/.cache/kinect/gllibs:$LD_LIBRARY_PATH"

2c. Tracker self-check

tracker/.venv/bin/python -m pytest tests/test_tracker.py -v   # data-path suite, 9/9 green

3. Provision a user-space OpenNI2 runtime

The verified Linux consumer links against a real libOpenNI2.so. If OpenNI2 is not installed system-wide and you have no sudo, stage it into ~/.local/openni2-root from the Debian/Ubuntu packages using the same apt-get download + dpkg-deb -x pattern as the GL workaround:

mkdir -p ~/.local/openni2-root
cd /tmp
apt-get download libopenni2-0 libopenni2-dev
for d in libopenni2-0_*.deb libopenni2-dev_*.deb; do
  dpkg-deb -x "$d" ~/.local/openni2-root
done

After this you should have, under ~/.local/openni2-root/usr:

  • include/openni2/OpenNI.h (plus the OniDriverAPI.h custom-driver headers needed by the SynthKinect driver, which this repo vendors under fallback/linux-openni2/vendor/openni2/),
  • lib/x86_64-linux-gnu/libOpenNI2.so and libOpenNI2.so.0,
  • lib/x86_64-linux-gnu/OpenNI2/Drivers/ holding the stock drivers (libPS1080.so.0, libOniFile.so.0, libDummyDevice.so.0, libPSLink.so.0).

This particular libOpenNI2.so scans only <libdir>/OpenNI2/Drivers for *.so.0 files (no OPENNI2_DRIVERS_PATH env var is honored), which is why the build step in step 4 copies the SynthKinect driver into that exact directory.

4. Build the OpenNI2 SynthKinect driver

cmake -S fallback/linux-openni2 -B fallback/linux-openni2/build
cmake --build fallback/linux-openni2/build

This is an isolated CMake project (it does not touch the root build). It compiles the driver libSynthKinect.so.0 from core/synth + core/mapping (reused directly, never duplicated) and the independent openni2_depth_consumer binary, then deploys libSynthKinect.so.0 into ~/.local/openni2-root/usr/lib/x86_64-linux-gnu/OpenNI2/Drivers/ so the OpenNI2 loader finds it.

OPENNI2_ROOT defaults to $HOME/.local/openni2-root; override the cache var if yours lives elsewhere.

4a. About the frame source

The deployed driver (libSynthKinect.so.0) reads live frames from the shared-memory contract region virtual_kinect_frames (ShmFrameSource), the same region the tracker publishes to. So a publisher must be running for the driver to emit a body: run openni2_depth_consumer with no tracker publishing and it reads all-zero frames (non_zero=0), by design, not a failure of the driver. The verified moving-depth result comes from the full end-to-end run in step 5, which starts the tracker first.

LD_LIBRARY_PATH=$HOME/.local/openni2-root/usr/lib/x86_64-linux-gnu \
  fallback/linux-openni2/build/openni2_depth_consumer 12

5. Run the full end-to-end validation

This is the reproduction target: recorded video -> live MediaPipe tracker -> shared-memory IPC contract -> SynthKinect OpenNI2 driver -> an independent OpenNI2 consumer observing moving, articulated depth.

export PATH="$HOME/.local/bin:$PATH"
export LD_LIBRARY_PATH="$HOME/.cache/kinect/gllibs:$LD_LIBRARY_PATH"
tracker/.venv/bin/python tools/e2e_linux_validation/run_e2e.py

The harness, with no pytest and no mocks (every step is the real binary/process):

  1. generates a deterministic recorded video of a real photographed human panning across frames (never a live webcam, so the run is reproducible),
  2. builds the SynthKinect driver and the depth_stats_consumer,
  3. runs the real tracker (python -m tracker.tracker) against that video at 320x240, publishing real MediaPipe pose + mask frames into the frozen IPC contract,
  4. runs openni2_depth_consumer, which reads moving depth frames through OpenNI2,
  5. runs depth_stats_consumer, a second independent OpenNI2 consumer asserting a per-frame depth spread of at least 100 mm (an articulated body surface, not a flat 800 mm floor).

Expected result: VERDICT: PASS. An observed run on the build host read 12 in-band depth frames with a moving silhouette (max centroid displacement ~75 px) and ARTICULATED DEPTH CONFIRMED: max per-frame spread 191mm across 12 frames, with body depth in the ~2300-2530 mm band. A non-zero exit means the consumer saw fewer than 10 in-band moving frames, or the depth never spread past the 100 mm articulation threshold.

If you supply NiTE2 (non-redistributable, not shipped here), point a NiTE2 skeleton sample at the same OpenNI2 device to additionally get a tracked skeleton. Without NiTE2 you still get the verified depth + enumeration result above.

6. The USB device-attach path (optional, [~] not verified here)

Instead of the OpenNI2 driver, you can present the emitter as a real USB device so any Kinect v1 OpenNI/libfreenect app binds to it. This needs the usbip userspace and a loaded vhci-hcd controller, neither of which is available on the WSL2 kernel this repo was built on. On a native-Linux host where usbip is packaged:

cmake -S attach/linux -B attach/linux/build && cmake --build attach/linux/build
./attach/linux/build/kinect_attach serve --port 3240          # exports 1-1 camera, 1-2 audio, 1-3 motor
sudo modprobe vhci-hcd
./attach/linux/build/kinect_attach attach --host 127.0.0.1 --port 3240 --busid 1-1
lsusb | grep 045e                                             # expect 045e:02ae

Repeat attach for --busid 1-2 and 1-3. See attach/linux/README.md for the full runbook and the WSL2 caveats. This path proves IS-1 (the OS enumerates a Kinect); the OpenNI2 driver path in steps 1-5 proves the depth/synthesis fidelity.