Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpKinect.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
110 class VISP_EXPORT vpKinect : public Freenect::FreenectDevice
111 {
112 //private:
113 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
114 // vpKinect(const vpKinect &); // Not implemented!
115 // vpKinect &operator=(const vpKinect &){
116 // throw vpException(vpException::functionNotImplementedError,"Not implemented!");
117 // return *this;
118 // }
119 //#endif
120 
121 public:
125  typedef enum {
127  DMAP_MEDIUM_RES
128  } vpDMResolution;
129 
130  vpKinect(freenect_context *ctx, int index);
131  virtual ~vpKinect();
132 
133  void start(vpKinect::vpDMResolution res = DMAP_LOW_RES);
134  void stop();
135 
136  bool getDepthMap(vpImage<float>& map);
137  bool getDepthMap(vpImage<float>& map, vpImage<unsigned char>& Imap);
138  bool getRGB(vpImage<vpRGBa>& IRGB);
139 
140 
141  inline void getIRCamParameters(vpCameraParameters &cam) const {
142  cam = IRcam;
143  }
144  inline void getRGBCamParameters(vpCameraParameters &cam) const {
145  cam = RGBcam;
146  }
147  inline void setIRCamParameters(const vpCameraParameters &cam) {
148  IRcam = cam;
149  }
150  inline void setRGBCamParameters(const vpCameraParameters &cam) {
151  RGBcam = cam;
152  }
153 
154  void warpRGBFrame(const vpImage<vpRGBa> & Irgb, const vpImage<float> & Idepth, vpImage<vpRGBa> & IrgbWarped);//warp the RGB image into the Depth camera frame
155 
156  private:
158  // Do not call directly even in child
159  void VideoCallback(void* rgb, uint32_t timestamp);
160 
161  // Do not call directly even in child
162  void DepthCallback(void* depth, uint32_t timestamp);
163 
164  private:
165  vpMutex m_rgb_mutex;
166  vpMutex m_depth_mutex;
167 
168  vpCameraParameters RGBcam, IRcam;//intrinsic parameters of the two cameras
169  vpHomogeneousMatrix rgbMir;//Transformation from IRcam coordinate frame to RGBcam coordinate frame.
170  vpHomogeneousMatrix irMrgb;//Transformation from RGBcam coordinate frame to IRcam coordinate frame .
171  vpDMResolution DMres;
172  unsigned int hd;//height of the depth map
173  unsigned int wd;//width of the depth map
174 
175  //Access protected by a mutex:
176  vpImage<float> dmap;
177  vpImage<vpRGBa> IRGB;
178  bool m_new_rgb_frame;
179  bool m_new_depth_map;
180  bool m_new_depth_image;
181  unsigned int height;//height of the rgb image
182  unsigned int width;//width of the rgb image
183 
184 };
185 
186 #endif
187 
188 #endif
void getRGBCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:144
vpDMResolution
Definition: vpKinect.h:125
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setIRCamParameters(const vpCameraParameters &cam)
Definition: vpKinect.h:147
Driver for the Kinect-1 device.
Definition: vpKinect.h:110
Generic class defining intrinsic camera parameters.
void getIRCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:141
void setRGBCamParameters(const vpCameraParameters &cam)
Definition: vpKinect.h:150