File: README.rdoc

package info (click to toggle)
libfreenect 1%3A0.5.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,156 kB
  • sloc: ansic: 7,417; cpp: 7,265; cs: 2,062; python: 992; ruby: 873; java: 730; xml: 49; sh: 27; makefile: 23
file content (86 lines) | stat: -rw-r--r-- 2,102 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
= ffi-libfreenect

FFI-based Ruby wrapper for the OpenKinect libfreenect library.

== Requirements
  * ffi >= 0.5.0

== Installation

=== via Gem

    (sudo)? gem install ffi-libfreenect

=== via Rake

    git clone http://github.com/jgrunzweig/ffi-libfreenect.git
    cd ffi-libfreenect
    (sudo)? gem install jeweler
    rake install

=== Synopsis

    require 'freenect'

    ctx = Freenect.init()
    devs = ctx.num_devices

    STDERR.puts "Number of Kinects detected: #{devs}"
    unless devs > 0
      STDERR.puts "Error: no kinect detected"
      exit 1
    end

    STDERR.puts "Selecting device 0"
    dev = ctx.open_device(0)

    dev.set_led(:red)   # play with the led
    dev.set_tilt_degrees(30)  # tilt up to max
    sleep 1
    dev.set_tilt_degrees(-30) # tilt down to max
    sleep 1
    dev.set_tilt_degrees(0.0) # tilt back to center
    sleep 1
    dev.set_led(:green)   # play with the led

    # Actual video and depth capture work similarly to eachother.
    # But they're still both pretty un-sugary.
    #
    # Future versions will probably abstract this and try to make it more 
    # ruby-ish.
    #
    # The example below shows how to write a single video frame to a PPM file.

    dev.depth_mode = Freenect.depth_mode(:medium, :depth_11bit)
	dev.video_mode = Freenect.video_mode(:medium, :rgb)
    dev.start_depth()
    dev.start_video()

    $snapshot_finished = nil

    STDERR.puts "Taking snapshot"
    dev.set_video_callback do |device, video, timestamp|
      if not $snapshot_finished
        fname = "%u.ppm" % timestamp
        STDERR.puts "Writing #{fname}"
        File.open(fname, "w") do |f|
          f.puts("P6 %d %d 255\n" % [ dev.video_mode.width, dev.video_mode.height ] )
		  f.write(video.read_string_length(dev.video_mode.bytes))
		end
        $snapshot_finished = true
      end
    end

    until $snapshot_finished 
      break if (ctx.process_events < 0)
    end

    dev.set_led(:off)
    dev.stop_depth
    dev.stop_video
    dev.close
    ctx.close

== Copyright

Copyright (c) 2010 Josh Grunzweig & Eric Monti. See LICENSE.txt for details.