58 : FreenectDevice( ctx, index )
60 m_rgb_buffer = (
unsigned char *) malloc( FREENECT_RGB_SIZE );
61 m_depth_buffer = (uint16_t *) malloc( FREENECT_DEPTH_SIZE );
68 free( m_depth_buffer );
80 memcpy( (
void *) m_rgb_buffer, (
void *) rgb, FREENECT_RGB_SIZE );
81 m_depth_timestamp = timestamp;
93 memcpy( (
void *) m_depth_buffer, (
void *) depth, FREENECT_DEPTH_SIZE );
94 m_depth_timestamp = timestamp;
112 return m_depth_buffer;
119 : m_freenect_dev( 0 ),
122 m_image_num( FALSE_COLOR_DEPTH_IMAGE ),
124 m_false_color_depth_buffer( 0 )
127 m_freenect_ctx =
new Freenect::Freenect< FvFreenectDevice >();
129 for (
unsigned int i = 0; i < 2048; ++i )
131 float v = i / 2048.0;
133 m_gamma[i] = v * 6 * 256;
140 delete m_freenect_ctx;
148 m_freenect_dev = &( m_freenect_ctx->createDevice( 0 ) );
151 catch( std::runtime_error& e )
156 m_false_color_depth_buffer = (
unsigned char*) malloc( FREENECT_RGB_SIZE );
167 m_freenect_dev->startRGB();
168 m_freenect_dev->startDepth();
171 catch( std::runtime_error& e )
185 m_freenect_dev->stopRGB();
186 m_freenect_dev->stopDepth();
189 catch( std::runtime_error& e )
199 m_freenect_ctx->deleteDevice( 0 );
200 free( m_false_color_depth_buffer );
206 if ( !m_started || !m_opened ) {
return; }
210 for (
unsigned int i = 0; i < FREENECT_FRAME_PIX; ++i )
213 int pval = m_gamma[ depth[i] ];
214 int lb = pval & 0xff;
217 m_false_color_depth_buffer[3*i+0] = 255;
218 m_false_color_depth_buffer[3*i+1] = 255-lb;
219 m_false_color_depth_buffer[3*i+2] = 255-lb;
223 m_false_color_depth_buffer[3*i+0] = 255;
224 m_false_color_depth_buffer[3*i+1] = lb;
225 m_false_color_depth_buffer[3*i+2] = 0;
229 m_false_color_depth_buffer[3*i+0] = 255-lb;
230 m_false_color_depth_buffer[3*i+1] = 255;
231 m_false_color_depth_buffer[3*i+2] = 0;
235 m_false_color_depth_buffer[3*i+0] = 0;
236 m_false_color_depth_buffer[3*i+1] = 255;
237 m_false_color_depth_buffer[3*i+2] = lb;
241 m_false_color_depth_buffer[3*i+0] = 0;
242 m_false_color_depth_buffer[3*i+1] = 255-lb;
243 m_false_color_depth_buffer[3*i+2] = 255;
247 m_false_color_depth_buffer[3*i+0] = 0;
248 m_false_color_depth_buffer[3*i+1] = 0;
249 m_false_color_depth_buffer[3*i+2] = 255-lb;
253 m_false_color_depth_buffer[3*i+0] = 0;
254 m_false_color_depth_buffer[3*i+1] = 0;
255 m_false_color_depth_buffer[3*i+2] = 0;
287 return FREENECT_RGB_SIZE;
298 return FREENECT_FRAME_W;
304 return FREENECT_FRAME_H;
317 switch ( m_image_num )
321 printf(
"Selected RGB buffer\n" );
325 m_buffer = m_false_color_depth_buffer;
326 printf(
"Selected false color depth buffer\n" );
unsigned char * rgb_buffer()
Access the RGB buffer.
static const unsigned int FALSE_COLOR_DEPTH_IMAGE
False color depth image.
virtual void dispose_buffer()
Dispose current buffer.
virtual void set_image_number(unsigned int n)
Set image number to retrieve.
virtual bool ready()
Camera is ready for taking pictures.
virtual void open()
Open the camera.
void DepthCallback(void *depth, uint32_t timestamp)
Callback function for the freenect driver.
virtual unsigned int buffer_size()
Size of buffer.
virtual void stop()
Stop image transfer from the camera.
uint16_t * depth_buffer()
Access the depth buffer.
virtual colorspace_t colorspace()
Colorspace of returned image.
void RGBCallback(freenect_pixel *rgb, uint32_t timestamp)
Callback function for the freenect driver.
KinectCamera(const CameraArgumentParser *cap=NULL)
Constructor.
virtual unsigned char * buffer()
Get access to current image buffer.
virtual void start()
Start image transfer from the camera.
virtual unsigned int pixel_height()
Height of image in pixels.
static const unsigned int RGB_IMAGE
Color image.
FvFreenectDevice(freenect_context *ctx, int index)
Constructor.
virtual void flush()
Flush image queue.
virtual unsigned int pixel_width()
Width of image in pixels.
~FvFreenectDevice()
Destructor.
virtual void print_info()
Print out camera information.
virtual void capture()
Capture an image.
virtual void close()
Close camera.
~KinectCamera()
Destructor.