ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
kinectAcquisition.cpp
1 /****************************************************************************
2  *
3  * $Id: kinectAcquisition.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Kinect example.
36  *
37  * Authors:
38  * C�line Teuli�re
39  *
40  *****************************************************************************/
41 
42 
51 #include <visp/vpConfig.h>
52 #include <iostream>
53 #ifdef VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES
54 
55 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI))
56 
57 
58 #include <visp/vpImage.h>
59 #include <visp/vpDisplayX.h>
60 #include <visp/vpDisplayGTK.h>
61 #include <visp/vpDisplayOpenCV.h>
62 #include <visp/vpDisplayGDI.h>
63 #include <visp/vpKinect.h>
64 #include <visp/vpTime.h>
65 
66 int main() {
67  // Init Kinect
68 #ifdef VISP_HAVE_LIBFREENECT_OLD
69  // This is the way to initialize Freenect with an old version of libfreenect packages under ubuntu lucid 10.04
70  Freenect::Freenect<vpKinect> freenect;
71  vpKinect & kinect = freenect.createDevice(0);
72 #else
73  Freenect::Freenect freenect;
74  vpKinect & kinect = freenect.createDevice<vpKinect>(0);
75 #endif
76 
77  // Set tilt angle in degrees
78  if (0) {
79  float angle = -3;
80  kinect.setTiltDegrees(angle);
81  }
82 
83  // Init display
84 #if 1
85  kinect.start(vpKinect::DMAP_MEDIUM_RES); // Start acquisition thread with a depth map resolution of 480x640
86  vpImage<unsigned char> Idmap(480,640);//for medium resolution
87  vpImage<float> dmap(480,640);//for medium resolution
88 #else
89  kinect.start(vpKinect::DMAP_LOW_RES); // Start acquisition thread with a depth map resolution of 240x320 (default resolution)
90  vpImage<unsigned char> Idmap(240,320);//for low resolution
91  vpImage<float> dmap(240,320);//for low resolution
92 #endif
93  vpImage<vpRGBa> Irgb(480,640),Iwarped(480,640);
94 
95 #if defined VISP_HAVE_X11
96  vpDisplayX display, displayRgb, displayRgbWarped;
97 #elif defined VISP_HAVE_GTK
98  vpDisplayGTK display;
99  vpDisplayGTK displayRgb;
100  vpDisplayGTK displayRgbWarped;
101 #elif defined VISP_HAVE_OPENCV
102  vpDisplayOpenCV display;
103  vpDisplayOpenCV displayRgb;
104  vpDisplayOpenCV displayRgbWarped;
105 #elif defined VISP_HAVE_GDI
106  vpDisplayGDI display;
107  vpDisplayGDI displayRgb;
108  vpDisplayGDI displayRgbWarped;
109 #endif
110 
111  display.init(Idmap, 100, 200,"Depth map");
112  displayRgb.init(Irgb, 900, 200,"Color Image");
113  displayRgbWarped.init(Iwarped,900,700,"Warped Color Image");
114 
115  // A click to stop acquisition
116  std::cout << "Click in one image to stop acquisition" << std::endl;
117 
118  while(!vpDisplay::getClick(Idmap,false) && !vpDisplay::getClick(Irgb,false))
119  {
120  kinect.getDepthMap(dmap);
121  kinect.getDepthMap(dmap, Idmap);
122  kinect.getRGB(Irgb);
123 
124  vpDisplay::display(Idmap);
125  vpDisplay::flush(Idmap);
126  vpDisplay::display(Irgb);
127  vpDisplay::flush(Irgb);
128 
129  //Warped RGB image:
130  kinect.warpRGBFrame(Irgb,dmap, Iwarped);
131  vpDisplay::display(Iwarped);
132  vpDisplay::flush(Iwarped);
133  }
134  std::cout << "Stop acquisition" << std::endl;
135  kinect.stop(); // Stop acquisition thread
136  return 0;
137 }
138 
139 #else
140 
141 int
142 main()
143 {
144  std::cout << "You should install a video device (X11, GTK, OpenCV, GDI) to run this example" << std::endl;
145 }
146 #endif
147 
148 #else
149 int
150 main()
151 {
152  std::cout << "You should install libfreenect to run this example" << std::endl;
153 }
154 
155 #endif
156 
157