MRPT  1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
12 #include <mrpt/system/CTicTac.h>
13 #include <mrpt/img/CImage.h>
14 #include <iostream>
15 
16 using namespace mrpt;
17 using namespace mrpt::gui;
18 using namespace mrpt::obs;
19 using namespace mrpt::hwdrivers;
20 using namespace mrpt::img;
21 using namespace std;
22 
23 // ------------------------------------------------------
24 // TestCameraCaptureAsk
25 // ------------------------------------------------------
27 {
29 
30  if (!cam)
31  {
32  cerr << "The user didn't pick any camera. Exiting." << endl;
33  return;
34  }
35 
36  CDisplayWindow win("Live video");
37 
38  cout << "Press 's' to save frames.\nClose the window to exit.\n";
39 
40  double counter = 0;
41  mrpt::system::CTicTac tictac;
42 
43  while (win.isOpen())
44  {
45  if (!counter) tictac.Tic();
46 
47  mrpt::obs::CObservation::Ptr obs = cam->getNextFrame();
48  ASSERT_(obs);
49 
50  CImage* img = nullptr;
51 
52  if (IS_CLASS(obs, CObservationImage))
53  {
55  std::dynamic_pointer_cast<CObservationImage>(obs);
56  img = &o->image;
57  }
58  else if (IS_CLASS(obs, CObservationStereoImages))
59  {
61  std::dynamic_pointer_cast<CObservationStereoImages>(obs);
62  img = &o->imageRight;
63  }
64  else if (IS_CLASS(obs, CObservation3DRangeScan))
65  {
67  std::dynamic_pointer_cast<CObservation3DRangeScan>(obs);
68  if (o->hasIntensityImage) img = &o->intensityImage;
69  }
70 
71  if (img) win.showImage(*img);
72 
73  if (++counter == 10)
74  {
75  double t = tictac.Tac();
76  cout << "Frame Rate: " << counter / t << " fps" << endl;
77  counter = 0;
78  }
79 
80  // Process keystrokes:
82  {
83  const int key_code = mrpt::system::os::getch();
84  switch (key_code)
85  {
86  case 's':
87  case 'S':
88  {
89  static int cnt = 0;
90  const std::string sFile =
91  mrpt::format("frame%05i.png", cnt++);
92  cout << "Saving frame to: " << sFile << endl;
93  img->saveToFile(sFile);
94  }
95  break;
96  default:
97  break;
98  };
99  }
100 
101  std::this_thread::sleep_for(2ms);
102  }
103 
104  cout << "Closing..." << endl;
105 }
106 
107 // ------------------------------------------------------
108 // MAIN
109 // ------------------------------------------------------
110 int main()
111 {
112  try
113  {
115 
116  return 0;
117  }
118  catch (std::exception& e)
119  {
120  std::cout << "MRPT exception caught: " << e.what() << std::endl;
121  return -1;
122  }
123  catch (...)
124  {
125  printf("Untyped exception!!");
126  return -1;
127  }
128 }
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
GLdouble GLdouble t
Definition: glext.h:3689
CCameraSensor::Ptr prepareVideoSourceFromUserSelection()
Show to the user a list of possible camera drivers and creates and open the selected camera...
int getch() noexcept
An OS-independent version of getch, which waits until a key is pushed.
Definition: os.cpp:370
A high-performance stopwatch, with typical resolution of nanoseconds.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
Contains classes for various device interfaces.
STL namespace.
int counter
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
GLint GLvoid * img
Definition: glext.h:3763
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
This namespace contains representation of robot actions and observations.
mrpt::gui::CDisplayWindow3D::Ptr win
GLsizei const GLchar ** string
Definition: glext.h:4101
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
Definition: CObject.h:102
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:390
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
void TestCameraCaptureAsk()
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020