Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpKinect.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * API for using a Microsoft Kinect device
33  * Requires libfreenect as a third party library
34  *
35  * Authors:
36  * Celine Teuliere
37  *
38  *****************************************************************************/
39 
40 #ifndef _vpKinect_h_
41 #define _vpKinect_h_
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/vpCameraParameters.h>
51 #include <visp3/core/vpHomogeneousMatrix.h>
52 #include <visp3/core/vpImage.h>
53 #include <visp3/core/vpMeterPixelConversion.h>
54 #include <visp3/core/vpMutex.h> // need pthread
55 #include <visp3/core/vpPixelMeterConversion.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
117  // implemented!"); 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  inline void getIRCamParameters(vpCameraParameters &cam) const { cam = IRcam; }
141  inline void getRGBCamParameters(vpCameraParameters &cam) const { cam = RGBcam; }
142  inline void setIRCamParameters(const vpCameraParameters &cam) { IRcam = cam; }
143  inline void setRGBCamParameters(const vpCameraParameters &cam) { RGBcam = cam; }
144 
145  void warpRGBFrame(const vpImage<vpRGBa> &Irgb, const vpImage<float> &Idepth,
146  vpImage<vpRGBa> &IrgbWarped); // warp the RGB image into
147  // the Depth camera frame
148 
149 private:
151  // Do not call directly even in child
152  void VideoCallback(void *rgb, uint32_t timestamp);
153 
154  // Do not call directly even in child
155  void DepthCallback(void *depth, uint32_t timestamp);
156 
157 private:
158  vpMutex m_rgb_mutex;
159  vpMutex m_depth_mutex;
160 
161  vpCameraParameters RGBcam, IRcam; // intrinsic parameters of the two cameras
162  vpHomogeneousMatrix rgbMir; // Transformation from IRcam coordinate frame to
163  // RGBcam coordinate frame.
164  vpHomogeneousMatrix irMrgb; // Transformation from RGBcam coordinate frame
165  // to IRcam coordinate frame .
166  vpDMResolution DMres;
167  unsigned int hd; // height of the depth map
168  unsigned int wd; // width of the depth map
169 
170  // Access protected by a mutex:
171  vpImage<float> dmap;
172  vpImage<vpRGBa> IRGB;
173  bool m_new_rgb_frame;
174  bool m_new_depth_map;
175  bool m_new_depth_image;
176  unsigned int height; // height of the rgb image
177  unsigned int width; // width of the rgb image
178 };
179 
180 #endif
181 
182 #endif
void getRGBCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:141
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:142
Driver for the Kinect-1 device.
Definition: vpKinect.h:110
Generic class defining intrinsic camera parameters.
void getIRCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:140
void setRGBCamParameters(const vpCameraParameters &cam)
Definition: vpKinect.h:143