Visual Servoing Platform  version 3.3.0
kinectAcquisition.cpp
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  * Kinect example.
33  *
34  * Authors:
35  * Celine Teuliere
36  *
37  *****************************************************************************/
38 
47 #include <iostream>
48 #include <visp3/core/vpConfig.h>
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 #include <visp3/core/vpImage.h>
54 #include <visp3/core/vpTime.h>
55 #include <visp3/gui/vpDisplayGDI.h>
56 #include <visp3/gui/vpDisplayGTK.h>
57 #include <visp3/gui/vpDisplayOpenCV.h>
58 #include <visp3/gui/vpDisplayX.h>
59 #include <visp3/sensor/vpKinect.h>
60 
61 int main()
62 {
63  try {
64 // Init Kinect
65 #ifdef VISP_HAVE_LIBFREENECT_OLD
66  // This is the way to initialize Freenect with an old version of
67  // libfreenect packages under ubuntu lucid 10.04
68  Freenect::Freenect<vpKinect> freenect;
69  vpKinect &kinect = freenect.createDevice(0);
70 #else
71  Freenect::Freenect freenect;
72  vpKinect &kinect = freenect.createDevice<vpKinect>(0);
73 #endif
74 
75  // Set tilt angle in degrees
76  if (0) {
77  float angle = -3;
78  kinect.setTiltDegrees(angle);
79  }
80 
81 // Init display
82 #if 1
83  kinect.start(vpKinect::DMAP_MEDIUM_RES); // Start acquisition thread with
84  // a depth map resolution of
85  // 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
90  // depth map resolution of 240x320
91  // (default resolution)
92  vpImage<unsigned char> Idmap(240, 320); // for low resolution
93  vpImage<float> dmap(240, 320); // for low resolution
94 #endif
95  vpImage<vpRGBa> Irgb(480, 640), Iwarped(480, 640);
96 
97 #if defined VISP_HAVE_X11
98  vpDisplayX display, displayRgb, displayRgbWarped;
99 #elif defined VISP_HAVE_GTK
100  vpDisplayGTK display;
101  vpDisplayGTK displayRgb;
102  vpDisplayGTK displayRgbWarped;
103 #elif defined VISP_HAVE_OPENCV
104  vpDisplayOpenCV display;
105  vpDisplayOpenCV displayRgb;
106  vpDisplayOpenCV displayRgbWarped;
107 #elif defined VISP_HAVE_GDI
108  vpDisplayGDI display;
109  vpDisplayGDI displayRgb;
110  vpDisplayGDI displayRgbWarped;
111 #endif
112 
113  display.init(Idmap, 100, 200, "Depth map");
114  displayRgb.init(Irgb, 900, 200, "Color Image");
115  displayRgbWarped.init(Iwarped, 900, 700, "Warped Color Image");
116 
117  // A click to stop acquisition
118  std::cout << "Click in one image to stop acquisition" << std::endl;
119 
120  while (!vpDisplay::getClick(Idmap, false) && !vpDisplay::getClick(Irgb, false)) {
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 EXIT_SUCCESS;
138  } catch (const vpException &e) {
139  std::cout << "Catch an exception: " << e << std::endl;
140  return EXIT_FAILURE;
141  } catch (...) {
142  std::cout << "Catch an exception " << std::endl;
143  return EXIT_FAILURE;
144  }
145 }
146 
147 #else
148 
149 int main()
150 {
151  std::cout << "You do not have X11, or GDI (Graphical Device Interface), or GTK, or OpenCV functionalities to display images..." << std::endl;
152  std::cout << "Tip if you are on a unix-like system:" << std::endl;
153  std::cout << "- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
154  std::cout << "Tip if you are on a windows-like system:" << std::endl;
155  std::cout << "- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
156  return EXIT_SUCCESS;
157 }
158 #endif
159 
160 #else
161 int main()
162 {
163  std::cout << "You do not have Freenect functionality enabled" << std::endl;
164  std::cout << "Tip if you are on a unix-like system:" << std::endl;
165  std::cout << "- Install libfreenect, configure again ViSP using cmake and build again this example" << std::endl;
166  return EXIT_SUCCESS;
167 }
168 #endif
vpDisplayX
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:149
vpKinect::getDepthMap
bool getDepthMap(vpImage< float > &map)
Definition: vpKinect.cpp:172
vpKinect::start
void start(vpKinect::vpDMResolution res=DMAP_LOW_RES)
Definition: vpKinect.cpp:72
vpKinect::DMAP_MEDIUM_RES
Definition: vpKinect.h:125
vpDisplayGDI
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:127
vpDisplayOpenCV
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Definition: vpDisplayOpenCV.h:140
vpKinect::warpRGBFrame
void warpRGBFrame(const vpImage< vpRGBa > &Irgb, const vpImage< float > &Idepth, vpImage< vpRGBa > &IrgbWarped)
Definition: vpKinect.cpp:244
vpKinect::DMAP_LOW_RES
Definition: vpKinect.h:124
vpDisplay::display
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay_uchar.cpp:739
vpDisplayGTK
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:136
vpKinect::getRGB
bool getRGB(vpImage< vpRGBa > &IRGB)
Definition: vpKinect.cpp:230
vpKinect::stop
void stop()
Definition: vpKinect.cpp:115
vpDisplayWin32::init
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Definition: vpDisplayWin32.cpp:78
vpKinect
Driver for the Kinect-1 device.
Definition: vpKinect.h:108
vpDisplay::flush
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay_uchar.cpp:715
vpImage< unsigned char >
vpDisplay::getClick
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Definition: vpDisplay_uchar.cpp:764
vpException
error that can be emited by ViSP classes.
Definition: vpException.h:70