Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
testOccipitalStructure_Core_images.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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  * Image acquisition with Structure Core sensor and libStructure.
32  */
33 
40 #include <iostream>
41 
42 #include <visp3/core/vpConfig.h>
43 
44 #if defined(VISP_HAVE_OCCIPITAL_STRUCTURE) && ( VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11 ) \
45  && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
46 
47 #include <visp3/core/vpImageConvert.h>
48 #include <visp3/gui/vpDisplayGDI.h>
49 #include <visp3/gui/vpDisplayX.h>
50 #include <visp3/sensor/vpOccipitalStructure.h>
51 
52 int main()
53 {
54 #ifdef ENABLE_VISP_NAMESPACE
55  using namespace VISP_NAMESPACE_NAME;
56 #endif
57  try {
58  double t;
59  unsigned int display_scale = 1;
61 
62  ST::CaptureSessionSettings settings;
63  settings.source = ST::CaptureSessionSourceId::StructureCore;
64  settings.structureCore.visibleEnabled = true;
65  settings.applyExpensiveCorrection = true; // Apply a correction and clean filter to the depth before streaming.
66 
67  sc.open(settings);
68 
69  vpImage<float> I_depth_raw;
70  vpImage<vpRGBa> I_depth;
71  vpImage<vpRGBa> I_visible;
72 
73 #if defined(VISP_HAVE_X11)
74  vpDisplayX display_visible; // Visible image
75  vpDisplayX display_depth; // Depth image
76 #elif defined(VISP_HAVE_GDI)
77  vpDisplayGDI display_visible; // Visible image
78  vpDisplayGDI display_depth; // Depth image
79 #endif
80 
81 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
82  I_visible =
84  display_visible.setDownScalingFactor(display_scale);
85  display_visible.init(I_visible, 10, 10, "Visible image");
86 
87  I_depth_raw =
90  display_depth.setDownScalingFactor(display_scale);
91  display_depth.init(I_depth, static_cast<int>(I_visible.getWidth() / display_scale) + 20, 10, "Depth image");
92 #endif
93 
94  while (true) {
96 
97  sc.acquire((unsigned char *)I_visible.bitmap, (unsigned char *)I_depth_raw.bitmap);
98 
99  vpDisplay::display(I_visible);
100  vpDisplay::displayText(I_visible, 15 * display_scale, 15 * display_scale, "Click to quit", vpColor::red);
101  vpDisplay::flush(I_visible);
102 
103  vpImageConvert::createDepthHistogram(I_depth_raw, I_depth);
104  vpDisplay::display(I_depth);
105  vpDisplay::displayText(I_depth, 15 * display_scale, 15 * display_scale, "Click to quit", vpColor::red);
106  vpDisplay::flush(I_depth);
107 
108  if (vpDisplay::getClick(I_visible, false) || vpDisplay::getClick(I_depth, false))
109  break;
110 
111  std::cout << "Loop time: " << vpTime::measureTimeMs() - t << std::endl;
112  }
113  }
114  catch (const vpException &e) {
115  std::cerr << "Structure SDK error " << e.what() << std::endl;
116  }
117  catch (const std::exception &e) {
118  std::cerr << e.what() << std::endl;
119  }
120 
121  return EXIT_SUCCESS;
122 }
123 #else
124 int main()
125 {
126 #if !defined(VISP_HAVE_OCCIPITAL_STRUCTURE)
127  std::cout << "You do not have Occipital Structure SDK functionality enabled..." << std::endl;
128  std::cout << "Tip:" << std::endl;
129  std::cout << "- Install libStructure, configure again ViSP using cmake and build again this example" << std::endl;
130  return EXIT_SUCCESS;
131 #elif ( VISP_CXX_STANDARD < VISP_CXX_STANDARD_11 )
132  std::cout << "You do not build ViSP with c++11 or higher compiler flag" << std::endl;
133  std::cout << "Tip:" << std::endl;
134  std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
135 #elif !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
136  std::cout << "You don't have X11 or GDI display capabilities" << std::endl;
137 #endif
138  return EXIT_SUCCESS;
139 }
140 #endif
static const vpColor red
Definition: vpColor.h:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
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)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Definition: vpException.h:60
const char * what() const
Definition: vpException.cpp:71
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
unsigned int getWidth() const
Definition: vpImage.h:242
Type * bitmap
points toward the bitmap
Definition: vpImage.h:135
unsigned int getHeight(vpOccipitalStructureStream stream_type)
void acquire(vpImage< unsigned char > &gray, bool undistorted=false, double *ts=nullptr)
unsigned int getWidth(vpOccipitalStructureStream stream_type)
bool open(const ST::CaptureSessionSettings &settings)
VISP_EXPORT double measureTimeMs()