Skip to main content

A python wrapper for the kinect built on pylibfreenect2

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ktb-0.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

ktb-0.0.1-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file ktb-0.0.1.tar.gz.

File metadata

  • Download URL: ktb-0.0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for ktb-0.0.1.tar.gz
Algorithm Hash digest
SHA256 27f6b09191a7c598824a4f1951d87f1ff89a89c87e55195211de6da22fb79e9d
MD5 756b8f79e41483524250becf2fdb3082
BLAKE2b-256 15adbc74e58690a333424594ac37a340d2fae4d8b67280f38e941a0164a3b89c

See more details on using hashes here.

File details

Details for the file ktb-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ktb-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for ktb-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a6a4bcd1696d8578d6cb9a8977feabd6021ca3162096f0456b57e221905522d
MD5 e2ec0c926f87ff134ec93bad5a2d2ecc
BLAKE2b-256 47af8564f7af4951b80d94d79ec5a84f07ec51224cc79252beed8000efd379e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page