ViSP
kinectAcquisition.cpp
1 /****************************************************************************
2  *
3  * $Id: kinectAcquisition.cpp 5060 2014-12-12 18:31:03Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  * Celine Teuliere
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  try {
68  // Init Kinect
69 #ifdef VISP_HAVE_LIBFREENECT_OLD
70  // This is the way to initialize Freenect with an old version of libfreenect packages under ubuntu lucid 10.04
71  Freenect::Freenect<vpKinect> freenect;
72  vpKinect & kinect = freenect.createDevice(0);
73 #else
74  Freenect::Freenect freenect;
75  vpKinect & kinect = freenect.createDevice<vpKinect>(0);
76 #endif
77 
78  // Set tilt angle in degrees
79  if (0) {
80  float angle = -3;
81  kinect.setTiltDegrees(angle);
82  }
83 
84  // Init display
85 #if 1
86  kinect.start(vpKinect::DMAP_MEDIUM_RES); // Start acquisition thread with a depth map resolution of 480x640
87  vpImage<unsigned char> Idmap(480,640);//for medium resolution
88  vpImage<float> dmap(480,640);//for medium resolution
89 #else
90  kinect.start(vpKinect::DMAP_LOW_RES); // Start acquisition thread with a depth map resolution of 240x320 (default resolution)
91  vpImage<unsigned char> Idmap(240,320);//for low resolution
92  vpImage<float> dmap(240,320);//for low resolution
93 #endif
94  vpImage<vpRGBa> Irgb(480,640),Iwarped(480,640);
95 
96 #if defined VISP_HAVE_X11
97  vpDisplayX display, displayRgb, displayRgbWarped;
98 #elif defined VISP_HAVE_GTK
99  vpDisplayGTK display;
100  vpDisplayGTK displayRgb;
101  vpDisplayGTK displayRgbWarped;
102 #elif defined VISP_HAVE_OPENCV
103  vpDisplayOpenCV display;
104  vpDisplayOpenCV displayRgb;
105  vpDisplayOpenCV displayRgbWarped;
106 #elif defined VISP_HAVE_GDI
107  vpDisplayGDI display;
108  vpDisplayGDI displayRgb;
109  vpDisplayGDI displayRgbWarped;
110 #endif
111 
112  display.init(Idmap, 100, 200,"Depth map");
113  displayRgb.init(Irgb, 900, 200,"Color Image");
114  displayRgbWarped.init(Iwarped,900,700,"Warped Color Image");
115 
116  // A click to stop acquisition
117  std::cout << "Click in one image to stop acquisition" << std::endl;
118 
119  while(!vpDisplay::getClick(Idmap,false) && !vpDisplay::getClick(Irgb,false))
120  {
121  kinect.getDepthMap(dmap);
122  kinect.getDepthMap(dmap, Idmap);
123  kinect.getRGB(Irgb);
124 
125  vpDisplay::display(Idmap);
126  vpDisplay::flush(Idmap);
127  vpDisplay::display(Irgb);
128  vpDisplay::flush(Irgb);
129 
130  //Warped RGB image:
131  kinect.warpRGBFrame(Irgb,dmap, Iwarped);
132  vpDisplay::display(Iwarped);
133  vpDisplay::flush(Iwarped);
134  }
135  std::cout << "Stop acquisition" << std::endl;
136  kinect.stop(); // Stop acquisition thread
137  return 0;
138  }
139  catch(vpException e) {
140  std::cout << "Catch an exception: " << e << std::endl;
141  return 1;
142  }
143  catch(...) {
144  std::cout << "Catch an exception " << std::endl;
145  return 1;
146  }
147 }
148 
149 #else
150 
151 int
152 main()
153 {
154  std::cout << "You should install a video device (X11, GTK, OpenCV, GDI) to run this example" << std::endl;
155 }
156 #endif
157 
158 #else
159 int
160 main()
161 {
162  std::cout << "You should install libfreenect to run this example" << std::endl;
163 }
164 
165 #endif
166 
167 
void start(vpKinect::vpDMResolution res=DMAP_LOW_RES)
Definition: vpKinect.cpp:83
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
Define the X11 console to display images.
Definition: vpDisplayX.h:152
error that can be emited by ViSP classes.
Definition: vpException.h:76
Driver for the Kinect device.
Definition: vpKinect.h:112
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
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:145
bool getRGB(vpImage< vpRGBa > &IRGB)
Definition: vpKinect.cpp:246
void warpRGBFrame(const vpImage< vpRGBa > &Irgb, const vpImage< float > &Idepth, vpImage< vpRGBa > &IrgbWarped)
Definition: vpKinect.cpp:259
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void stop()
Definition: vpKinect.cpp:124
virtual bool getClick(bool blocking=true)=0
bool getDepthMap(vpImage< float > &map)
Definition: vpKinect.cpp:183