hornetseye-kinect 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -25
- data/Rakefile +1 -1
- data/ext/kinectcontext.cc +20 -14
- data/ext/kinectcontext.hh +2 -2
- data/ext/kinectinput.cc +20 -10
- metadata +3 -3
data/README.md
CHANGED
@@ -64,36 +64,16 @@ Here is another example displaying RGB and the depth image while keeping the til
|
|
64
64
|
require 'hornetseye_kinect'
|
65
65
|
require 'hornetseye_xorg'
|
66
66
|
include Hornetseye
|
67
|
-
class Numeric
|
68
|
-
def clip( range )
|
69
|
-
[ [ self, range.begin ].max, range.end ].min
|
70
|
-
end
|
71
|
-
end
|
72
|
-
colours = Sequence.ubytergb 256
|
73
|
-
for i in 0...256
|
74
|
-
hue = 240 - i * 240.0 / 256.0
|
75
|
-
colours[i] =
|
76
|
-
RGB( ( ( hue - 180 ).abs - 60 ).clip( 0...60 ) * 0xFF / 60.0,
|
77
|
-
( 120 - ( hue - 120 ).abs ).clip( 0...60 ) * 0xFF / 60.0,
|
78
|
-
( 120 - ( hue - 240 ).abs ).clip( 0...60 ) * 0xFF / 60.0 )
|
79
|
-
end
|
80
67
|
input = KinectInput.new
|
81
|
-
display = X11Display.new
|
82
|
-
output_depth, output_video = XImageOutput.new, XVideoOutput.new
|
83
|
-
window_depth = X11Window.new display, output_depth, 640, 480
|
84
|
-
window_video = X11Window.new display, output_video, 640, 480
|
85
|
-
window_depth.title = 'Depth'
|
86
|
-
window_video.title = 'Video'
|
87
|
-
window_depth.show
|
88
|
-
window_video.show
|
89
68
|
input.led = KinectInput::LED_RED
|
90
|
-
|
69
|
+
img = MultiArray.ubytergb 1280, 480
|
70
|
+
X11Display.show :output => XVideoOutput do
|
71
|
+
img[ 0 ... 640, 0 ... 480 ] = input.read_video
|
72
|
+
img[ 640 ... 1280, 0 ... 480 ] = ( input.read_depth >> 2 ).clip
|
91
73
|
input.tilt = 0.0
|
92
74
|
input.get_state
|
93
75
|
moving = input.tilt_status == KinectInput::TILT_STATUS_MOVING
|
94
76
|
input.led = moving ? KinectInput::LED_RED : KinectInput::LED_GREEN
|
95
|
-
|
96
|
-
output_depth.write( ( input.read_depth >> 3 ).lut colours )
|
97
|
-
display.process_events
|
77
|
+
img
|
98
78
|
end
|
99
79
|
|
data/Rakefile
CHANGED
data/ext/kinectcontext.cc
CHANGED
@@ -26,10 +26,11 @@ using namespace std;
|
|
26
26
|
VALUE KinectContext::cRubyClass = Qnil;
|
27
27
|
|
28
28
|
KinectContext::KinectContext(void) throw (Error):
|
29
|
-
|
30
|
-
m_instances(0)
|
29
|
+
m_usb(NULL), m_context(NULL), m_mutex(PTHREAD_MUTEX_INITIALIZER),
|
30
|
+
m_cond(PTHREAD_COND_INITIALIZER), m_instances(0)
|
31
31
|
{
|
32
|
-
|
32
|
+
ERRORMACRO( libusb_init( &m_usb ) == 0, Error, , "Error creating libusb session" );
|
33
|
+
freenect_init( &m_context, m_usb );
|
33
34
|
ERRORMACRO( m_context != NULL, Error, , "Initialisation of libfreenect failed" );
|
34
35
|
}
|
35
36
|
|
@@ -63,6 +64,10 @@ void KinectContext::close(void)
|
|
63
64
|
freenect_shutdown( m_context );
|
64
65
|
m_context = NULL;
|
65
66
|
};
|
67
|
+
if ( m_usb != NULL ) {
|
68
|
+
libusb_exit( m_usb );
|
69
|
+
m_usb = NULL;
|
70
|
+
};
|
66
71
|
}
|
67
72
|
|
68
73
|
freenect_context *KinectContext::get(void) throw (Error)
|
@@ -77,9 +82,13 @@ void KinectContext::lock(void)
|
|
77
82
|
pthread_mutex_lock( &m_mutex );
|
78
83
|
}
|
79
84
|
|
80
|
-
void KinectContext::wait(void)
|
85
|
+
void KinectContext::wait(void) throw (Error)
|
81
86
|
{
|
82
|
-
|
87
|
+
struct timeval tv;
|
88
|
+
tv.tv_sec = 1;
|
89
|
+
tv.tv_usec = 0;
|
90
|
+
ERRORMACRO( libusb_handle_events_timeout( m_usb, &tv ) == 0, Error, ,
|
91
|
+
"Error processing USB events" );
|
83
92
|
}
|
84
93
|
|
85
94
|
void KinectContext::unlock(void)
|
@@ -87,12 +96,6 @@ void KinectContext::unlock(void)
|
|
87
96
|
pthread_mutex_unlock( &m_mutex );
|
88
97
|
}
|
89
98
|
|
90
|
-
void KinectContext::processEvents(void) throw (Error)
|
91
|
-
{
|
92
|
-
ERRORMACRO( freenect_process_events( m_context ) >= 0, Error, , "Error processing "
|
93
|
-
"USB events" );
|
94
|
-
}
|
95
|
-
|
96
99
|
string KinectContext::inspect(void) const
|
97
100
|
{
|
98
101
|
ostringstream s;
|
@@ -105,9 +108,12 @@ void KinectContext::threadFunc(void)
|
|
105
108
|
bool quit = false;
|
106
109
|
while ( !quit ) {
|
107
110
|
lock();
|
108
|
-
if ( m_instances > 0 )
|
109
|
-
|
110
|
-
|
111
|
+
if ( m_instances > 0 ) {
|
112
|
+
try {
|
113
|
+
wait();
|
114
|
+
} catch ( Error &e ) {
|
115
|
+
};
|
116
|
+
} else {
|
111
117
|
pthread_cond_signal( &m_cond );
|
112
118
|
quit = true;
|
113
119
|
};
|
data/ext/kinectcontext.hh
CHANGED
@@ -30,10 +30,9 @@ public:
|
|
30
30
|
void close(void);
|
31
31
|
void addInstance(void);
|
32
32
|
void removeInstance(void);
|
33
|
-
void processEvents(void) throw (Error);
|
34
33
|
freenect_context *get(void) throw (Error);
|
35
34
|
void lock(void);
|
36
|
-
void wait(void);
|
35
|
+
void wait(void) throw (Error);
|
37
36
|
void unlock(void);
|
38
37
|
static VALUE cRubyClass;
|
39
38
|
static VALUE registerRubyClass( VALUE module );
|
@@ -43,6 +42,7 @@ public:
|
|
43
42
|
protected:
|
44
43
|
void threadFunc(void);
|
45
44
|
static void *staticThreadFunc( void *self );
|
45
|
+
libusb_context *m_usb;
|
46
46
|
freenect_context *m_context;
|
47
47
|
pthread_t m_thread;
|
48
48
|
pthread_mutex_t m_mutex;
|
data/ext/kinectinput.cc
CHANGED
@@ -85,11 +85,16 @@ FramePtr KinectInput::readVideo(void) throw (Error)
|
|
85
85
|
ERRORMACRO( m_device != NULL, Error, , "Kinect device is not open. "
|
86
86
|
"Did you call \"close\" before?" );
|
87
87
|
m_context->lock();
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
try {
|
89
|
+
while ( !m_haveRGB ) m_context->wait();
|
90
|
+
m_haveRGB = false;
|
91
|
+
char *data = m_rgb[ 2 ];
|
92
|
+
m_rgb[ 2 ] = m_rgb[ 1 - m_currentRGB ];
|
93
|
+
m_rgb[ 1 - m_currentRGB ] = data;
|
94
|
+
} catch ( Error &e ) {
|
95
|
+
m_context->unlock();
|
96
|
+
throw e;
|
97
|
+
};
|
93
98
|
m_context->unlock();
|
94
99
|
FramePtr retVal = FramePtr
|
95
100
|
( new Frame( "UBYTERGB", FREENECT_FRAME_W, FREENECT_FRAME_H, m_rgb[ 2 ] ) );
|
@@ -101,11 +106,16 @@ FramePtr KinectInput::readDepth(void) throw (Error)
|
|
101
106
|
ERRORMACRO( m_device != NULL, Error, , "Kinect device is not open. "
|
102
107
|
"Did you call \"close\" before?" );
|
103
108
|
m_context->lock();
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
+
try {
|
110
|
+
while ( !m_haveDepth ) m_context->wait();
|
111
|
+
m_haveDepth = false;
|
112
|
+
char *data = m_depth[ 2 ];
|
113
|
+
m_depth[ 2 ] = m_depth[ 1 - m_currentDepth ];
|
114
|
+
m_depth[ 1 - m_currentDepth ] = data;
|
115
|
+
} catch ( Error &e ) {
|
116
|
+
m_context->unlock();
|
117
|
+
throw e;
|
118
|
+
};
|
109
119
|
m_context->unlock();
|
110
120
|
FramePtr retVal = FramePtr
|
111
121
|
( new Frame( "USINT", FREENECT_FRAME_W, FREENECT_FRAME_H, m_depth[ 2 ] ) );
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jan Wedekind
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-14 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|