ViSP  3.0.0
kinectAcquisition.cpp
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  * Kinect example.
32  *
33  * Authors:
34  * Celine Teuliere
35  *
36  *****************************************************************************/
37 
38 
47 #include <visp3/core/vpConfig.h>
48 #include <iostream>
49 #ifdef VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES
50 
51 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI))
52 
53 
54 #include <visp3/core/vpImage.h>
55 #include <visp3/gui/vpDisplayX.h>
56 #include <visp3/gui/vpDisplayGTK.h>
57 #include <visp3/gui/vpDisplayOpenCV.h>
58 #include <visp3/gui/vpDisplayGDI.h>
59 #include <visp3/sensor/vpKinect.h>
60 #include <visp3/core/vpTime.h>
61 
62 int main() {
63  try {
64  // Init Kinect
65 #ifdef VISP_HAVE_LIBFREENECT_OLD
66  // This is the way to initialize Freenect with an old version of libfreenect packages under ubuntu lucid 10.04
67  Freenect::Freenect<vpKinect> freenect;
68  vpKinect & kinect = freenect.createDevice(0);
69 #else
70  Freenect::Freenect freenect;
71  vpKinect & kinect = freenect.createDevice<vpKinect>(0);
72 #endif
73 
74  // Set tilt angle in degrees
75  if (0) {
76  float angle = -3;
77  kinect.setTiltDegrees(angle);
78  }
79 
80  // Init display
81 #if 1
82  kinect.start(vpKinect::DMAP_MEDIUM_RES); // Start acquisition thread with a depth map resolution of 480x640
83  vpImage<unsigned char> Idmap(480,640);//for medium resolution
84  vpImage<float> dmap(480,640);//for medium resolution
85 #else
86  kinect.start(vpKinect::DMAP_LOW_RES); // Start acquisition thread with a depth map resolution of 240x320 (default resolution)
87  vpImage<unsigned char> Idmap(240,320);//for low resolution
88  vpImage<float> dmap(240,320);//for low resolution
89 #endif
90  vpImage<vpRGBa> Irgb(480,640),Iwarped(480,640);
91 
92 #if defined VISP_HAVE_X11
93  vpDisplayX display, displayRgb, displayRgbWarped;
94 #elif defined VISP_HAVE_GTK
95  vpDisplayGTK display;
96  vpDisplayGTK displayRgb;
97  vpDisplayGTK displayRgbWarped;
98 #elif defined VISP_HAVE_OPENCV
99  vpDisplayOpenCV display;
100  vpDisplayOpenCV displayRgb;
101  vpDisplayOpenCV displayRgbWarped;
102 #elif defined VISP_HAVE_GDI
103  vpDisplayGDI display;
104  vpDisplayGDI displayRgb;
105  vpDisplayGDI displayRgbWarped;
106 #endif
107 
108  display.init(Idmap, 100, 200,"Depth map");
109  displayRgb.init(Irgb, 900, 200,"Color Image");
110  displayRgbWarped.init(Iwarped,900,700,"Warped Color Image");
111 
112  // A click to stop acquisition
113  std::cout << "Click in one image to stop acquisition" << std::endl;
114 
115  while(!vpDisplay::getClick(Idmap,false) && !vpDisplay::getClick(Irgb,false))
116  {
117  kinect.getDepthMap(dmap);
118  kinect.getDepthMap(dmap, Idmap);
119  kinect.getRGB(Irgb);
120 
121  vpDisplay::display(Idmap);
122  vpDisplay::flush(Idmap);
123  vpDisplay::display(Irgb);
124  vpDisplay::flush(Irgb);
125 
126  //Warped RGB image:
127  kinect.warpRGBFrame(Irgb,dmap, Iwarped);
128  vpDisplay::display(Iwarped);
129  vpDisplay::flush(Iwarped);
130  }
131  std::cout << "Stop acquisition" << std::endl;
132  kinect.stop(); // Stop acquisition thread
133  return 0;
134  }
135  catch(vpException e) {
136  std::cout << "Catch an exception: " << e << std::endl;
137  return 1;
138  }
139  catch(...) {
140  std::cout << "Catch an exception " << std::endl;
141  return 1;
142  }
143 }
144 
145 #else
146 
147 int
148 main()
149 {
150  std::cout << "You should install a video device (X11, GTK, OpenCV, GDI) to run this example" << std::endl;
151 }
152 #endif
153 
154 #else
155 int
156 main()
157 {
158  std::cout << "You should install libfreenect to run this example" << std::endl;
159 }
160 
161 #endif
162 
163 
void start(vpKinect::vpDMResolution res=DMAP_LOW_RES)
Definition: vpKinect.cpp:78
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Define the X11 console to display images.
Definition: vpDisplayX.h:148
error that can be emited by ViSP classes.
Definition: vpException.h:73
Driver for the Kinect device.
Definition: vpKinect.h:107
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2233
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
The vpDisplayOpenCV allows to display image using the opencv library.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Definition: vpDisplayGTK.h:141
bool getRGB(vpImage< vpRGBa > &IRGB)
Definition: vpKinect.cpp:241
void warpRGBFrame(const vpImage< vpRGBa > &Irgb, const vpImage< float > &Idepth, vpImage< vpRGBa > &IrgbWarped)
Definition: vpKinect.cpp:254
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void stop()
Definition: vpKinect.cpp:119
virtual bool getClick(bool blocking=true)=0
bool getDepthMap(vpImage< float > &map)
Definition: vpKinect.cpp:178