Skip to main content

kinect-toolbox

Overview

This is a set of helper functions to make using the Microsoft Kinect V2 with python easier. Libfreenect2 provides a robust interface for the kinect but it follows a more "C++ like" design paradigm. With this wrapper the kinect can be used more like a cv2 webcam. This package provides methods to get color, depth, registered color, registered depth, and ir images, record video, get point clouds (quickly), and makes the kinect interface all around more pythonic.

Credit for point cloud acceleration methods goes to stackoverflow user Logic1.

Installation

  1. Install libfreenect2
  2. Update your paths:
    export LIBFREENECT2_INSTALL_PREFIX=~/freenect2
    export LD_LIBRARY_PATH=$HOME/freenect2/lib:$LD_LIBRARY_PATH
    
  3. Install required python packages:
    pip install -r requirements.txt
    
  4. Test installation:
    python test.py
    

This package has been tested on Ubuntu 18.04 with python3.6.

Usage

import cv2
import ktb

k = ktb.Kinect()
while True:
    # Specify as many types as you want here
    color_frame = k.get_frame(ktb.COLOR)

    cv2.imshow('frame', color_frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

Methods

Kinect()

The kinect class. Supports the following input arguments:

  • params_file: Kinect parameters file or dict. Parameters file can contain the kinect intrinsic parameters and a 3D transformation (which is applied to point clouds).
  • device_index: Use to interface with a specific device if more than one is connected.
  • headless: If true, will allow the kinect to collect and process data without a display. Connect the Kinect to a server and collect data remotely!
  • pipeline: Optionally pass a pylibfreenect2 pipeline that will be used with the kinect. Note that this will override the headless argument - Headless requires CUDA or OpenCL pipeline. Possible types are as follows:
    • OpenGLPacketPipeline
    • CpuPacketPipeline
    • OpenCLPacketPipeline
    • CudaPacketPipeline
    • OpenCLKdePacketPipeline

Kinect.get_frame()

Get a video frame from the kinect. Optionally specify a list of image types and the function will return a corresponding list of images. Available types are:

Frame Type Description
RAW_COLOR returns a 1920 x 1080 color image
RAW_DEPTH returns a 512 x 424 depth image (units are mm)
COLOR returns a 512 x 424 color image, registered to depth image
DEPTH returns a 512 x 424 undistorted depth, image (units are mm)
IR returns a 512 x 424 ir image

Note that depth images have units in millimeters. To display them in a window without clipping first rescale the values:

frame = frame / 4500.

Kinect.record()

Records a video from the kinect. Halts execution and opens a cv2 window displaying a stream from the kinect while writing the stream to disk. Optionally specify any of the above frame types to record that specific stream.

Kinect.get_ptcld()

Get a point cloud from the kinect. Returns an point cloud of size [512, 424, 3], corresponding a grid of xyz points. Optionally return a color map derived from the registered color image.

Metadata

Release files for ktb 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ktb 0.0.1
File Size Uploaded
ktb-0.0.1.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ktb 0.0.1
File Interpreter ABI Platform
ktb-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.8 kB

Release files / ktb-0.0.1.tar.gz

Download URL ktb-0.0.1.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
27f6b09191a7c598824a4f1951d87f1ff89a89c87e55195211de6da22fb79e9d
BLAKE2b-256 checksum
How to use checksums
15adbc74e58690a333424594ac37a340d2fae4d8b67280f38e941a0164a3b89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.9

Release files / ktb-0.0.1-py3-none-any.whl

Download URL ktb-0.0.1-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a6a4bcd1696d8578d6cb9a8977feabd6021ca3162096f0456b57e221905522d
BLAKE2b-256 checksum
How to use checksums
47af8564f7af4951b80d94d79ec5a84f07ec51224cc79252beed8000efd379e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page