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