Giter Site home page Giter Site logo

rust-openni2's Introduction

OpenNI2 for Rust

In-development Rust wrapper for OpenNI2. OpenNI2 is useful for working with multi-sensor cameras that can simultaneously serve color and depth streams, particularly sensors developed by PrimeSense (a founding member of the OpenNI software project) such as the Xbox Kinect, and ASUS Xtion.

App example

extern crate openni2;
use std::{thread, time};
use openni2::{Status, Device, Stream, SensorType, OniDepthPixel};
fn callback(stream: &Stream<OniDepthPixel>) {
    // This function is only invoked when a frame *is* available to read
    let frame = stream.read_frame().expect("Frame not available to read!");
    let px = frame.pixels();
    let closest = px.iter()
        .enumerate()
        .fold((0u16, 0u16, ::std::u16::MAX), |closest, (n, &depth)| {
            let (x, y) = (n as u16 % frame.width(), n as u16 / frame.width());
            if depth < closest.2 && depth != 0 {
                (x, y, depth)
            } else {
                closest
            }
    });
    println!("[{:-6} {:-6} {:-6}]", closest.0, closest.1, closest.2);
}
fn main() -> Result<(), Status> {
    // Initialize the library
    openni2::init()?;
    // Open the first device we find, or abort early
    let device = Device::open_default()?;
    // Get a handle for opening a stream from its depth sensor. If the device
    // didn't have a depth sensor, it would return `Err` and abort the program.
    let stream = device.create_stream(SensorType::DEPTH)?;
    // Register a callback that will be called, with the stream as its first
    // argument, whenever a new frame is ready. When the listener falls out of
    // scope, the callback will be unregistered.
    let _listener = stream.listener(callback)?;
    // Start the stream, then let the callback run until we kill the program
    // ourselves.
    stream.start()?;
    let heartbeat = time::Duration::from_millis(250);
    loop {
        thread::sleep(heartbeat);
    }
}

Examples

examples/data_dump.rs demonstrates interrogating devices and streams about their properties, as well as blocking for new frames.

examples/closest_point.rs demonstrates event-based callbacks, and finding the closest point in a depth map.

examples/device_callbacks.rs demonstrates device callbacks that detect newly connected/disconnected devices

examples/simple_viewer.rs is a video stream viewer with keyboard controls.

  • 1 views the color and depth streams overlayed
  • 2 views the color stream
  • 3 views the depth stream
  • m toggles video stream mirroring

rust-openni2's People

Contributors

toomanybees avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

levels3d icf3ver

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.