Visual Servoing Platform version 3.5.0
testOccipitalStructure_Core_images.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2021 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 * Image acquisition with Structure Core sensor and libStructure.
33 *
34 *****************************************************************************/
35
42#include <iostream>
43
44#include <visp3/core/vpConfig.h>
45
46#if defined( VISP_HAVE_OCCIPITAL_STRUCTURE ) && ( VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11 ) && \
47 ( defined( VISP_HAVE_X11 ) || defined( VISP_HAVE_GDI ) )
48
49#include <visp3/core/vpImageConvert.h>
50#include <visp3/gui/vpDisplayGDI.h>
51#include <visp3/gui/vpDisplayX.h>
52#include <visp3/sensor/vpOccipitalStructure.h>
53
54int
55main()
56{
57 try
58 {
59 double t;
60 unsigned int display_scale = 1;
62
63 ST::CaptureSessionSettings settings;
64 settings.source = ST::CaptureSessionSourceId::StructureCore;
65 settings.structureCore.visibleEnabled = true;
66 settings.applyExpensiveCorrection = true; // Apply a correction and clean filter to the depth before streaming.
67
68 sc.open( settings );
69
70 vpImage< float > I_depth_raw;
71 vpImage< vpRGBa > I_depth;
72 vpImage< vpRGBa > I_visible;
73
74#if defined( VISP_HAVE_X11 )
75 vpDisplayX display_visible; // Visible image
76 vpDisplayX display_depth; // Depth image
77#elif defined( VISP_HAVE_GDI )
78 vpDisplayGDI display_visible; // Visible image
79 vpDisplayGDI display_depth; // Depth image
80#endif
81
82#if defined( VISP_HAVE_X11 ) || defined( VISP_HAVE_GDI )
85 display_visible.setDownScalingFactor( display_scale );
86 display_visible.init( I_visible, 10, 10, "Visible image" );
87
88 I_depth_raw =
90 I_depth =
92 display_depth.setDownScalingFactor( display_scale );
93 display_depth.init( I_depth, static_cast< int >( I_visible.getWidth() / display_scale ) + 20, 10, "Depth image" );
94#endif
95
96 while ( true )
97 {
99
100 sc.acquire( (unsigned char *)I_visible.bitmap, (unsigned char *)I_depth_raw.bitmap );
101
102 vpDisplay::display( I_visible );
103 vpDisplay::displayText( I_visible, 15 * display_scale, 15 * display_scale, "Click to quit", vpColor::red );
104 vpDisplay::flush( I_visible );
105
106 vpImageConvert::createDepthHistogram( I_depth_raw, I_depth );
107 vpDisplay::display( I_depth );
108 vpDisplay::displayText( I_depth, 15 * display_scale, 15 * display_scale, "Click to quit", vpColor::red );
109 vpDisplay::flush( I_depth );
110
111 if ( vpDisplay::getClick( I_visible, false ) || vpDisplay::getClick( I_depth, false ) )
112 break;
113
114 std::cout << "Loop time: " << vpTime::measureTimeMs() - t << std::endl;
115 }
116 }
117 catch ( const vpException &e )
118 {
119 std::cerr << "Structure SDK error " << e.what() << std::endl;
120 }
121 catch ( const std::exception &e )
122 {
123 std::cerr << e.what() << std::endl;
124 }
125
126 return EXIT_SUCCESS;
127}
128#else
129int
130main()
131{
132#if !defined( VISP_HAVE_OCCIPITAL_STRUCTURE )
133 std::cout << "You do not have Occipital Structure SDK functionality enabled..." << std::endl;
134 std::cout << "Tip:" << std::endl;
135 std::cout << "- Install libStructure, configure again ViSP using cmake and build again this example" << std::endl;
136 return EXIT_SUCCESS;
137#elif ( VISP_CXX_STANDARD < VISP_CXX_STANDARD_11 )
138 std::cout << "You do not build ViSP with c++11 or higher compiler flag" << std::endl;
139 std::cout << "Tip:" << std::endl;
140 std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
141#elif !( defined( VISP_HAVE_X11 ) || defined( VISP_HAVE_GDI ) )
142 std::cout << "You don't have X11 or GDI display capabilities" << std::endl;
143#endif
144 return EXIT_SUCCESS;
145}
146#endif
static const vpColor red
Definition: vpColor.h:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:135
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)
virtual void setDownScalingFactor(unsigned int scale)
Definition: vpDisplay.cpp:231
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 emited by ViSP classes.
Definition: vpException.h:72
const char * what() const
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
unsigned int getWidth() const
Definition: vpImage.h:246
Type * bitmap
points toward the bitmap
Definition: vpImage.h:143
unsigned int getHeight(vpOccipitalStructureStream stream_type)
void acquire(vpImage< unsigned char > &gray, bool undistorted=false, double *ts=NULL)
unsigned int getWidth(vpOccipitalStructureStream stream_type)
bool open(const ST::CaptureSessionSettings &settings)
VISP_EXPORT double measureTimeMs()