Fawkes API  Fawkes Development Version
kinect.h
00001 
00002 /***************************************************************************
00003  *  kinect.h - Microsoft Kinect 3D Camera using the freenect driver
00004  *
00005  *  Created: Fri Nov 26 10:46:09 2010
00006  *  Copyright  2010  Daniel Beck
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __FIREVISION_CAMS_KINECT_H_
00025 #define __FIREVISION_CAMS_KINECT_H_
00026 
00027 #include "camera.h"
00028 
00029 #include <libfreenect.hpp>
00030 
00031 namespace firevision {
00032 #if 0 /* just to make Emacs auto-indent happy */
00033 }
00034 #endif
00035 
00036 class CameraArgumentParser;
00037 
00038 class FvFreenectDevice : public Freenect::FreenectDevice
00039 {
00040  public:
00041   FvFreenectDevice( freenect_context* ctx, int index );
00042   ~FvFreenectDevice();
00043 
00044   void RGBCallback( freenect_pixel* rgb, uint32_t timestamp );
00045   void DepthCallback( void* depth, uint32_t timestamp );
00046 
00047   unsigned char* rgb_buffer();
00048   uint16_t*      depth_buffer();
00049 
00050  private:
00051   unsigned char* m_rgb_buffer;
00052   uint16_t*      m_depth_buffer;
00053 
00054   uint32_t m_rgb_timestamp;
00055   uint32_t m_depth_timestamp;
00056 };
00057 
00058 class KinectCamera : public Camera
00059 {
00060  public:
00061   KinectCamera( const CameraArgumentParser* cap = NULL );
00062   ~KinectCamera();
00063 
00064   virtual void open();
00065   virtual void start();
00066   virtual void stop();
00067   virtual void close();
00068   virtual void capture();
00069   virtual void flush();
00070 
00071   virtual bool ready();
00072 
00073   virtual void print_info();
00074 
00075   virtual unsigned char* buffer();
00076   virtual unsigned int   buffer_size();
00077   virtual void           dispose_buffer();
00078 
00079   virtual unsigned int pixel_width();
00080   virtual unsigned int pixel_height();
00081   virtual colorspace_t colorspace();
00082 
00083   virtual void set_image_number( unsigned int n );
00084 
00085  public:
00086   static const unsigned int RGB_IMAGE;
00087   static const unsigned int FALSE_COLOR_DEPTH_IMAGE;
00088 
00089  private:
00090   Freenect::Freenect< FvFreenectDevice >* m_freenect_ctx;
00091   FvFreenectDevice*                       m_freenect_dev;
00092 
00093   bool m_opened;
00094   bool m_started;
00095 
00096   unsigned int m_image_num;
00097 
00098   unsigned char* m_buffer;
00099   unsigned char* m_false_color_depth_buffer;
00100 
00101   uint16_t m_gamma[2048];
00102 };
00103 
00104 } // end namespace firevision
00105 
00106 #endif /* __FIREVISION_CAMS_KINECT_H_ */