Visual Servoing Platform  version 3.0.0
vpKinect.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * API for using a Microsoft Kinect device
32  * Requires libfreenect as a third party library
33  *
34  * Authors:
35  * Celine Teuliere
36  *
37  *****************************************************************************/
38 
39 
40 #ifndef __VP_KINECT__
41 #define __VP_KINECT__
42 
43 #include <visp3/core/vpConfig.h>
44 // Note that libfreenect needs libusb-1.0 and libpthread
45 #if defined(VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES)
46 
47 #include <iostream>
48 #include <libfreenect.hpp>
49 
50 #include <visp3/core/vpMutex.h> // need pthread
51 #include <visp3/core/vpImage.h>
52 #include <visp3/core/vpHomogeneousMatrix.h>
53 #include <visp3/core/vpCameraParameters.h>
54 #include <visp3/core/vpPixelMeterConversion.h>
55 #include <visp3/core/vpMeterPixelConversion.h>
56 
107 class VISP_EXPORT vpKinect : public Freenect::FreenectDevice
108 {
109 //private:
110 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
111 // vpKinect(const vpKinect &); // Not implemented!
112 // vpKinect &operator=(const vpKinect &){
113 // throw vpException(vpException::functionNotImplementedError,"Not implemented!");
114 // return *this;
115 // }
116 //#endif
117 
118 public:
122  typedef enum {
124  DMAP_MEDIUM_RES
125  } vpDMResolution;
126 
127  vpKinect(freenect_context *ctx, int index);
128  virtual ~vpKinect();
129 
130  void start(vpKinect::vpDMResolution res = DMAP_LOW_RES);
131  void stop();
132 
133  bool getDepthMap(vpImage<float>& map);
134  bool getDepthMap(vpImage<float>& map, vpImage<unsigned char>& Imap);
135  bool getRGB(vpImage<vpRGBa>& IRGB);
136 
137 
138  inline void getIRCamParameters(vpCameraParameters &cam) const {
139  cam = IRcam;
140  }
141  inline void getRGBCamParameters(vpCameraParameters &cam) const {
142  cam = RGBcam;
143  }
144  inline void setIRCamParameters(const vpCameraParameters &cam) {
145  IRcam = cam;
146  }
147  inline void setRGBCamParameters(const vpCameraParameters &cam) {
148  RGBcam = cam;
149  }
150 
151  void warpRGBFrame(const vpImage<vpRGBa> & Irgb, const vpImage<float> & Idepth, vpImage<vpRGBa> & IrgbWarped);//warp the RGB image into the Depth camera frame
152 
153  private:
155  // Do not call directly even in child
156  void VideoCallback(void* rgb, uint32_t timestamp);
157 
158  // Do not call directly even in child
159  void DepthCallback(void* depth, uint32_t timestamp);
160 
161  private:
162  vpMutex m_rgb_mutex;
163  vpMutex m_depth_mutex;
164 
165  vpCameraParameters RGBcam, IRcam;//intrinsic parameters of the two cameras
166  vpHomogeneousMatrix rgbMir;//Transformation from IRcam coordinate frame to RGBcam coordinate frame.
167  vpHomogeneousMatrix irMrgb;//Transformation from RGBcam coordinate frame to IRcam coordinate frame .
168  vpDMResolution DMres;
169  unsigned int hd;//height of the depth map
170  unsigned int wd;//width of the depth map
171 
172  //Access protected by a mutex:
173  vpImage<float> dmap;
174  vpImage<vpRGBa> IRGB;
175  bool m_new_rgb_frame;
176  bool m_new_depth_map;
177  bool m_new_depth_image;
178  unsigned int height;//height of the rgb image
179  unsigned int width;//width of the rgb image
180 
181 };
182 
183 #endif
184 
185 #endif
void getRGBCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:141
vpDMResolution
Definition: vpKinect.h:122
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setIRCamParameters(const vpCameraParameters &cam)
Definition: vpKinect.h:144
Driver for the Kinect device.
Definition: vpKinect.h:107
Class that allows protection by mutex.
Definition: vpMutex.h:58
Generic class defining intrinsic camera parameters.
void getIRCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:138
void setRGBCamParameters(const vpCameraParameters &cam)
Definition: vpKinect.h:147