Main MRPT website > C++ reference for 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>
15 #include <iostream>
16 
17 using namespace mrpt::hwdrivers;
18 using namespace mrpt::gui;
19 using namespace mrpt::obs;
20 using namespace mrpt::system;
21 using namespace mrpt::io;
22 using namespace mrpt::serialization;
23 using namespace std;
24 
25 // ------------------------------------------------------
26 // TestCaptureOpenCV
27 // ------------------------------------------------------
28 bool LIVE_CAM = true;
29 int N_CAM_TO_OPEN = 0;
31 
32 void TestCapture_OpenCV()
33 {
34  CImageGrabber_OpenCV* capture = nullptr;
35 
36  if (LIVE_CAM)
37  {
38 #if 0 // test: Select the desired resolution
39  mrpt::vision::TCaptureCVOptions opts;
40  opts.frame_width = 320;
41  opts.frame_height = 240;
42  capture = new CImageGrabber_OpenCV( 0, CAMERA_CV_AUTODETECT, opts );
43 #else
45 #endif
46  }
47  else
48  {
49  capture = new CImageGrabber_OpenCV(AVI_TO_OPEN);
50  }
51 
52  CTicTac tictac;
53 
54  cout << "Press any key to stop capture to 'capture.rawlog'..." << endl;
55 
56  CFileGZOutputStream fil("./capture.rawlog");
57 
58  CDisplayWindow win("Capturing...");
59 
60  int cnt = 0;
61 
62  while (!mrpt::system::os::kbhit())
63  {
64  if ((cnt++ % 20) == 0)
65  {
66  if (cnt > 0)
67  {
68  double t = tictac.Tac();
69  double FPS = 20 / t;
70  printf("\n %f FPS\n", FPS);
71  }
72  tictac.Tic();
73  }
74 
76  mrpt::make_aligned_shared<CObservationImage>(); // Memory will be
77  // freed by
78  // SF destructor in each
79  // loop.
80  if (!capture->getObservation(*obs))
81  {
82  cerr << "Error retrieving images!" << endl;
83  break;
84  }
85 
86  archiveFrom(fil) << obs;
87 
88  cout << ".";
89  cout.flush();
90  if (win.isOpen()) win.showImage(obs->image);
91  }
92 
93  delete capture;
94 }
95 
96 int main(int argc, char** argv)
97 {
98  try
99  {
100  if (argc > 1)
101  {
102  if (!strstr(argv[1], ".avi"))
103  {
104  LIVE_CAM = true;
105  N_CAM_TO_OPEN = atoi(argv[1]);
106  }
107  else
108  {
109  LIVE_CAM = false;
110  AVI_TO_OPEN = argv[1];
111  }
112  }
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("Another exception!!");
126  return -1;
127  }
128 }
mrpt::system::os::kbhit
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:390
LIVE_CAM
bool LIVE_CAM
Definition: vision_stereo_rectify/test.cpp:28
mrpt::io
Definition: img/CImage.h:22
t
GLdouble GLdouble t
Definition: glext.h:3689
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
CFileGZOutputStream.h
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:22
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
CImageGrabber_OpenCV.h
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
TestCapture_OpenCV
void TestCapture_OpenCV()
Definition: vision_stereo_rectify/test.cpp:32
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::io::CFileGZOutputStream
Saves data to a file and transparently compress the data using the given compression level.
Definition: io/CFileGZOutputStream.h:26
mrpt::obs::CObservationImage::Ptr
std::shared_ptr< CObservationImage > Ptr
Definition: CObservationImage.h:37
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
mrpt::gui::CDisplayWindow
This class creates a window as a graphical user interface (GUI) for displaying images to the user.
Definition: CDisplayWindow.h:30
mrpt::hwdrivers::CAMERA_CV_AUTODETECT
@ CAMERA_CV_AUTODETECT
Definition: CImageGrabber_OpenCV.h:25
mrpt::serialization
Definition: aligned_serialization.h:14
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
N_CAM_TO_OPEN
int N_CAM_TO_OPEN
Definition: vision_stereo_rectify/test.cpp:29
mrpt::hwdrivers::CImageGrabber_OpenCV
A class for grabing images from a "OpenCV"-compatible camera, or from an AVI video file.
Definition: CImageGrabber_OpenCV.h:75
mrpt::serialization::archiveFrom
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
Definition: CArchive.h:561
CTicTac.h
AVI_TO_OPEN
std::string AVI_TO_OPEN
Definition: vision_stereo_rectify/test.cpp:30
string
GLsizei const GLchar ** string
Definition: glext.h:4101
CArchive.h
CDisplayWindow.h
mrpt::hwdrivers::CImageGrabber_OpenCV::getObservation
bool getObservation(mrpt::obs::CObservationImage &out_observation)
Grab an image from the opened camera.
Definition: CImageGrabber_OpenCV.cpp:250
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST