Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpKinect.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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) && defined(VISP_HAVE_THREADS)
46 
47 #include <iostream>
48 #include <libfreenect.hpp>
49 #include <mutex>
50 
51 #include <visp3/core/vpCameraParameters.h>
52 #include <visp3/core/vpHomogeneousMatrix.h>
53 #include <visp3/core/vpImage.h>
54 #include <visp3/core/vpMeterPixelConversion.h>
55 #include <visp3/core/vpPixelMeterConversion.h>
56 
57 BEGIN_VISP_NAMESPACE
114 class VISP_EXPORT vpKinect : public Freenect::FreenectDevice
115 {
116  // private:
117  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
118  // vpKinect(const vpKinect &); // Not implemented!
119  // vpKinect &operator=(const vpKinect &){
120  // throw vpException(vpException::functionNotImplementedError,"Not
121  // implemented!"); return *this;
122  // }
123  //#endif
124 
125 public:
129  typedef enum
130  {
132  DMAP_MEDIUM_RES
133  } vpDMResolution;
134 
135  vpKinect(freenect_context *ctx, int index);
136  virtual ~vpKinect();
137 
138  void start(vpKinect::vpDMResolution res = DMAP_LOW_RES);
139  void stop();
140 
141  bool getDepthMap(vpImage<float> &map);
142  bool getDepthMap(vpImage<float> &map, vpImage<unsigned char> &Imap);
143  bool getRGB(vpImage<vpRGBa> &IRGB);
144 
145  inline void getIRCamParameters(vpCameraParameters &cam) const { cam = IRcam; }
146  inline void getRGBCamParameters(vpCameraParameters &cam) const { cam = RGBcam; }
147  inline void setIRCamParameters(const vpCameraParameters &cam) { IRcam = cam; }
148  inline void setRGBCamParameters(const vpCameraParameters &cam) { RGBcam = cam; }
149 
150  void warpRGBFrame(const vpImage<vpRGBa> &Irgb, const vpImage<float> &Idepth,
151  vpImage<vpRGBa> &IrgbWarped); // warp the RGB image into
152  // the Depth camera frame
153 
154 private:
156  // Do not call directly even in child
157  void VideoCallback(void *rgb, uint32_t timestamp);
158 
159  // Do not call directly even in child
160  void DepthCallback(void *depth, uint32_t timestamp);
161 
162 private:
163  std::mutex m_rgb_mutex;
164  std::mutex m_depth_mutex;
165 
166  vpCameraParameters RGBcam, IRcam; // intrinsic parameters of the two cameras
167  vpHomogeneousMatrix rgbMir; // Transformation from IRcam coordinate frame to
168  // RGBcam coordinate frame.
169  vpHomogeneousMatrix irMrgb; // Transformation from RGBcam coordinate frame
170  // 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 END_VISP_NAMESPACE
185 #endif
186 
187 #endif
Generic class defining intrinsic camera parameters.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Driver for the Kinect-1 device.
Definition: vpKinect.h:115
vpDMResolution
Definition: vpKinect.h:130
@ DMAP_LOW_RES
Definition: vpKinect.h:131
void getIRCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:145
void setIRCamParameters(const vpCameraParameters &cam)
Definition: vpKinect.h:147
void setRGBCamParameters(const vpCameraParameters &cam)
Definition: vpKinect.h:148
void getRGBCamParameters(vpCameraParameters &cam) const
Definition: vpKinect.h:146