ruby-freenect 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gems ADDED
@@ -0,0 +1,12 @@
1
+ # .gems generated gem export file. Note that any env variable settings will be missing. Append these after using a ';' field separator
2
+ diff-lcs -v1.1.3
3
+ ffi -v1.0.11
4
+ git -v1.2.5
5
+ jeweler -v1.6.4
6
+ mkrf -v0.2.3
7
+ rake -v0.9.2.2
8
+ rspec -v2.7.0
9
+ rspec-core -v2.7.1
10
+ rspec-expectations -v2.7.0
11
+ rspec-mocks -v2.7.0
12
+ ruby-opengl2 -v0.60.3
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@ruby-freenect
@@ -0,0 +1,23 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2012 Troy Stribling
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
@@ -0,0 +1,204 @@
1
+ = ruby-freenect
2
+
3
+ FFI-based Ruby wrapper for the OpenKinect library. ruby-freenect supports the following,
4
+
5
+ * Video, IR and Depth
6
+ * LED
7
+ * Tilt
8
+ * Accelerometer
9
+
10
+ == Requirements
11
+
12
+ * libfreenect http://openkinect.org/wiki/Main_Page (See the section on installing libfreenect)
13
+ * Ruby 1.9.3 or greater
14
+ * Only tested on Ubuntu 10.04
15
+
16
+ == Interface
17
+
18
+ The interface is very simple. This section will give a brief description of all supported methods and attributes.
19
+
20
+ === Video and Depth Modes
21
+
22
+ Video and depth modes are used to configure the video and depth data streams and provide info about the streams. Both are instances of the FreenectFrameMode. FreenectFrameMode attributes are shown below and may be accessed with <tt>[]</tt>
23
+
24
+ * <b>:resolution</b> - Resolution
25
+ * <b>:format</b> - Video or depth format accessed using <tt>mode[:format][:video_format]</tt> or <tt>mode[:format][:depth_format]</tt>
26
+ * <b>:bytes</b> - Total buffer size in bytes to hold a single frame of data,
27
+ * <b>:width</b> - Width of the frame, in pixels
28
+ * <b>:height</b> - Height of the frame, in pixels
29
+ * <b>:data_bits_per_pixel</b> - Number of bits of information needed for each pixel
30
+ * <b>:padding_bits_per_pixel</b> - Number of bits of padding for alignment used for each pixel
31
+ * <b>:framerate</b> - Approximate expected frame rate, in Hz
32
+ * <b>:is_valid</b> - If 0 is invalid and does not describe a supported mode. Otherwise, the frame_mode is valid.
33
+
34
+ The supported resolutions are,
35
+
36
+ * <b>:freenect_resolution_medium</b> VGA - 640x480
37
+
38
+ The supported Depth Formats are.
39
+
40
+ * <b>:freenect_depth_11bit</b> - 11 bit depth information in one uint16_t/pixel
41
+ * <b>:freenect_depth_10bit</b> - 10 bit depth information in one uint16_t/pixel
42
+ * <b>:freenect_depth_11bit_packed</b> - 11 bit packed depth information
43
+ * <b>:freenect_depth_10bit_packed</b> - 10 bit packed depth information
44
+
45
+ The supported Video Formats are,
46
+
47
+ * <b>:freenect_video_rgb</b> - Decompressed RGB mode
48
+ * <b>:freenect_video_bayer</b> - Bayer compressed mode
49
+ * <b>:freenect_video_ir_8bit</b> - 8-bit IR mode
50
+ * <b>:freenect_video_ir_10bit</b> - 10-bit IR mode
51
+ * <b>:freenect_video_ir_10bit_packed</b> - 10-bit packed IR mode
52
+ * <b>:freenect_video_yuv_rgb</b> - YUV RGB mode
53
+ * <b>:freenect_video_yuv_raw</b> - YUV Raw mode
54
+
55
+ === Video Stream
56
+
57
+ The following methods are used to access and configure the video stream,
58
+
59
+ Return the number of supported video modes.
60
+
61
+ Freenect.get_video_mode_count
62
+
63
+ Return the video mode with the specified mode_id.
64
+
65
+ Freenect.get_video_mode(mode_id)
66
+
67
+ Return the configured video mode.
68
+
69
+ Freenect.get_current_video_mode
70
+
71
+ Return video mode with specified video_format.
72
+
73
+ Freenect.find_video_mode(video_format)
74
+
75
+ Return video frame with specified video_mode. This methods blocks until the video frame is available.
76
+
77
+ Freenect.get_video(video_mode)
78
+
79
+ === Depth Stream
80
+
81
+ The following methods are used to access and configure the depth stream,
82
+
83
+ Return the number of supported depth modes.
84
+
85
+ Freenect.get_depth_mode_count
86
+
87
+ Return the depth mode with the specified mode_id.
88
+
89
+ Freenect.get_depth_mode(mode_id)
90
+
91
+ Return the configured depth mode.
92
+
93
+ Freenect.get_current_depth_mode
94
+
95
+ Return depth mode with specified depth_format.
96
+
97
+ Freenect.find_depth_mode(depth_format)
98
+
99
+ Return video frame with specified video_mode. This methods blocks until the video frame is available.
100
+
101
+ Freenect.get_depth(depth_mode)
102
+
103
+ === Tilt
104
+
105
+ The following methods are used to access and change the kinect tilt configuration,
106
+
107
+ Set the Kinect tilt to the specified angle.
108
+
109
+ Freenect.set_tilt(angle)
110
+
111
+ Return the Kinect tilt state. Use the following methods to read the tilt state.
112
+
113
+ Freenect.get_tilt_state
114
+
115
+ Return the Kinect tilt angle from the tilt state.
116
+
117
+ Freenect.get_tilt(tilt_state)
118
+
119
+ Return the Kinect tilt status from the tilt state.
120
+
121
+ Freenect.get_tilt_status(tilt_state)
122
+
123
+ Return the acceleration vector components from the tilt state
124
+
125
+ Freenect.get_acceleration(tilt_state)
126
+
127
+ === LED
128
+
129
+ The following methods are used to change the LED status,
130
+
131
+ Freenect.set_led(led_option)
132
+
133
+ The supported values for LED Option are,
134
+
135
+ * <b>:led_off</b> Turn LED off
136
+ * <b>:led_green</b> Turn LED to Green
137
+ * <b>:led_red</b> Turn LED to Red
138
+ * <b>:led_yellow</b> Turn LED to Yellow
139
+ * <b>:led_blink_green</b> Make LED blink Green
140
+ * <b>:led_blink_red_yellow</b> Make LED blink Red/Yellow
141
+
142
+ === Miscellaneous methods
143
+
144
+ End the current session.
145
+
146
+ Freenect.stop
147
+
148
+ Return the number of Kinects.
149
+
150
+ Freenect.get_device_count
151
+
152
+
153
+ === Examples
154
+
155
+ Several examples can be found at https://github.com/troystribling/ruby-freenect/tree/master/examples. The examples require the ruby-opengl2 gem and the mkrf gem.
156
+
157
+ == Install libfreenect
158
+
159
+ If you have problems visit http://openkinect.org/wiki/Getting_Started#Manual_Build_on_Linux
160
+
161
+ === Prerequisites
162
+
163
+ sudo apt-get install cmake libglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev
164
+
165
+ sudo apt-get install autoconf automake
166
+
167
+ sudo apt-get install libltdl3-dev
168
+
169
+ === Build and Install libusb
170
+
171
+ git clone git://git.libusb.org/libusb.git
172
+
173
+ ./autogen.sh
174
+ make
175
+ sudo make install
176
+
177
+ === Build and Install libfreenect
178
+
179
+ git clone git://github.com/OpenKinect/libfreenect.git
180
+
181
+ cd libreenect
182
+ mkdir build
183
+ cd build
184
+ cmake ..
185
+
186
+ make
187
+ sudo make install
188
+
189
+ === Configure USB Interface
190
+
191
+ Add the following lines to the file <tt>usr-local-libs.conf</tt>
192
+
193
+ /usr/local/lib64
194
+ /usr/local/lib
195
+
196
+ Next enter the following commands
197
+
198
+ sudo su root
199
+ mv usr-local-libs.conf /etc/ld.so.conf.d/usr-local-libs.conf
200
+ /sbin/ldconfig -v
201
+
202
+ == Copyright
203
+
204
+ Copyright (c) 2012 Troy Stribling. See LICENSE.txt for details.
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ruby-freenect"
8
+ gem.summary = gem.description = %Q{Ruby bindings for the libfreenect Kinect driver}
9
+ gem.homepage = "https://github.com/troystribling/freenect4r"
10
+ gem.authors = ["Troy Stribling"]
11
+
12
+ gem.rdoc_options += ["--title", "FFI Freenect", "--main", "README.rdoc", "--line-numbers"]
13
+ gem.add_dependency("ffi", ">= 1.0.11")
14
+
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rspec/core/rake_task'
23
+ RSpec::Core::RakeTask.new(:spec) do |t|
24
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
25
+ t.pattern = 'spec/**/*_spec.rb'
26
+ end
27
+
28
+ RSpec::Core::RakeTask.new(:rcov) do |t|
29
+ t.rcov_opts = %q[--exclude "spec"]
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,31 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib")) << File.expand_path(File.dirname(__FILE__))
2
+ require 'rubygems'
3
+ require 'freenect'
4
+ require 'tools'
5
+ require 'opengl'
6
+ include Gl,Glu,Glut
7
+
8
+ puts "Opening Kinect"
9
+ depth_mode = Freenect.find_depth_mode(:freenect_depth_11bit)
10
+
11
+ display = lambda do
12
+ depth_buffer = Freenect.get_depth(depth_mode)
13
+ glPixelZoom(1.0, -1.0)
14
+ glRasterPos2i(-1, 1)
15
+ glDrawPixels(depth_mode[:width], depth_mode[:height], GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, depth_buffer)
16
+ glutSwapBuffers()
17
+ end
18
+
19
+ glutInit
20
+ glutInitWindowSize(depth_mode[:width], depth_mode[:height])
21
+ glutInitWindowPosition(100, 100)
22
+ glutCreateWindow($0)
23
+
24
+ glutDisplayFunc(display)
25
+ glutIdleFunc(display)
26
+ glutKeyboardFunc(sync_keyboard)
27
+
28
+ glClearColor(0.0, 0.0, 0.0, 0.0)
29
+ glClear(GL_COLOR_BUFFER_BIT)
30
+
31
+ glutMainLoop
@@ -0,0 +1,31 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib")) << File.expand_path(File.dirname(__FILE__))
2
+ require 'rubygems'
3
+ require 'freenect'
4
+ require 'tools'
5
+ require 'opengl'
6
+ include Gl,Glu,Glut
7
+
8
+ puts "Opening Kinect"
9
+ video_mode = Freenect.find_video_mode(:freenect_video_ir_10bit)
10
+
11
+ display = lambda do
12
+ video_buffer = Freenect.get_video(video_mode)
13
+ glPixelZoom(1.0, -1.0)
14
+ glRasterPos2i(-1, 1)
15
+ glDrawPixels(video_mode[:width], video_mode[:height], GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, video_buffer)
16
+ glutSwapBuffers()
17
+ end
18
+
19
+ glutInit
20
+ glutInitWindowSize(video_mode[:width], video_mode[:height])
21
+ glutInitWindowPosition(100, 100)
22
+ glutCreateWindow($0)
23
+
24
+ glutDisplayFunc(display)
25
+ glutIdleFunc(display)
26
+ glutKeyboardFunc(sync_keyboard)
27
+
28
+ glClearColor(0.0, 0.0, 0.0, 0.0)
29
+ glClear(GL_COLOR_BUFFER_BIT)
30
+
31
+ glutMainLoop
@@ -0,0 +1,29 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib")) << File.expand_path(File.dirname(__FILE__))
2
+ require 'freenect'
3
+ require 'tools'
4
+
5
+ video_mode_count = Freenect.get_video_mode_count
6
+ puts "Video Mode Count: #{video_mode_count}"
7
+ puts "Supported Video Modes"
8
+ video_mode_count.times do |mode_id|
9
+ frame_mode = Freenect.freenect_get_video_mode(mode_id)
10
+ puts "Mode ID: #{mode_id}"
11
+ print_video_mode(frame_mode)
12
+ end
13
+
14
+ depth_mode_count = Freenect.get_depth_mode_count
15
+ puts "Depth Mode Count: #{depth_mode_count}"
16
+ puts "Supported Depth Modes"
17
+ depth_mode_count.times do |mode_id|
18
+ frame_mode = Freenect.freenect_get_depth_mode(mode_id)
19
+ puts "Mode ID: #{mode_id}"
20
+ print_depth_mode(frame_mode)
21
+ end
22
+
23
+ puts "Find Video Mode with Resoultion ':freenect_resolution_medium' and Format ':freenect_video_rgb'"
24
+ frame_mode = Freenect.find_video_mode(:freenect_video_rgb, :freenect_resolution_medium)
25
+ print_video_mode(frame_mode)
26
+
27
+ puts "Find Depth Mode with Resoultion ':freenect_resolution_medium' and Format ':freenect_depth_11bit'"
28
+ frame_mode = Freenect.find_depth_mode(:freenect_depth_11bit, :freenect_resolution_medium)
29
+ print_depth_mode(frame_mode)
@@ -0,0 +1,21 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
2
+ require 'freenect'
3
+
4
+ puts "LED GREEN"
5
+ Freenect.set_led(:led_green)
6
+ sleep(5)
7
+ puts "LED RED"
8
+ Freenect.set_led(:led_red)
9
+ sleep(5)
10
+ puts "LED YELLOW"
11
+ Freenect.set_led(:led_yellow)
12
+ sleep(5)
13
+ puts "LED BLINK GREEN"
14
+ Freenect.set_led(:led_blink_green)
15
+ sleep(5)
16
+ puts "LED BLINK RED/YELLOW"
17
+ Freenect.set_led(:led_blink_red_yellow)
18
+ sleep(5)
19
+ puts "LED OFF"
20
+ Freenect.set_led(:led_off)
21
+ Freenect.stop
@@ -0,0 +1,17 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
2
+ require 'freenect'
3
+
4
+ [-25,-15,0,15,25,0].each do |angle|
5
+ puts "Set Tilt Angle: #{angle}"
6
+ tilt_state = Freenect.get_tilt_state
7
+ tilt_angle = Freenect.get_tilt(tilt_state)
8
+ tilt_status = Freenect.get_tilt_status(tilt_state)
9
+ acc = Freenect.get_acceleration(tilt_state)
10
+ puts "Current Tilt Angle: #{tilt_angle}"
11
+ puts "Tilt Status: #{tilt_status}"
12
+ puts "Acceleration: #{acc.inspect}"
13
+ Freenect.set_tilt(angle)
14
+ sleep(10)
15
+ end
16
+
17
+ Freenect.stop
@@ -0,0 +1,69 @@
1
+ def print_video_mode(frame_mode)
2
+ puts " Format: #{frame_mode[:format][:video_format]}"
3
+ print_frame_mode(frame_mode)
4
+ end
5
+
6
+ def print_depth_mode(frame_mode)
7
+ puts " Format: #{frame_mode[:format][:depth_format]}"
8
+ print_frame_mode(frame_mode)
9
+ end
10
+
11
+ def print_frame_mode(frame_mode)
12
+ puts " Resolution: #{frame_mode[:resolution]}"
13
+ puts " Bytes: #{frame_mode[:bytes]}"
14
+ puts " Width: #{frame_mode[:width]}"
15
+ puts " Height: #{frame_mode[:height]}"
16
+ puts " Data Bits Per Pixel: #{frame_mode[:data_bits_per_pixel]}"
17
+ puts " Padding Bits Per Pixel: #{frame_mode[:padding_bits_per_pixel]}"
18
+ puts " Framerate: #{frame_mode[:framerate]}"
19
+ puts " Is Valid: #{frame_mode[:is_valid]}"
20
+ end
21
+
22
+ def print_current_video_mode(device)
23
+ puts "Current Video Mode"
24
+ frame_mode = device.get_current_video_mode
25
+ print_video_mode(frame_mode)
26
+ end
27
+
28
+ def check_for_kinect(context)
29
+ kinect_count = context.get_device_count
30
+ if kinect_count == 0
31
+ puts "No Kinect Found"
32
+ exit(1)
33
+ else
34
+ puts "Number of Kinects: #{kinect_count}"
35
+ end
36
+ end
37
+
38
+ def sync_keyboard
39
+ tilt = 0
40
+ lambda do |key, x, y|
41
+ case (key.chr)
42
+ when ('0'..'5')
43
+ Freenect.set_led Freenect::FREENECT_LED_OPTIONS.symbols[key.chr.to_i]
44
+ when 'u'
45
+ Freenect.set_tilt (tilt = [25, tilt + 5].min)
46
+ when 'd'
47
+ Freenect.set_tilt (tilt = [-25, tilt - 5].max)
48
+ when 'c'
49
+ Freenect.set_tilt (tilt = 0)
50
+ when 'm'
51
+ depth_mode = Freenect.get_current_depth_mode
52
+ if depth_mode
53
+ puts "Current Depth Mode"
54
+ print_depth_mode(depth_mode)
55
+ end
56
+ video_mode = Freenect.get_current_video_mode
57
+ if video_mode
58
+ puts "Current Video Mode"
59
+ print_video_mode(video_mode)
60
+ end
61
+ when 'q'
62
+ Freenect.set_led :led_off
63
+ Freenect.set_tilt 0
64
+ Freenect.stop
65
+ puts "Closing Kinect"
66
+ exit(0)
67
+ end
68
+ end
69
+ end