MRPT  2.0.3
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
14 #include <mrpt/system/CTicTac.h>
15 #include <mrpt/system/os.h>
16 #include <iostream>
17 
18 using namespace mrpt::hwdrivers;
19 using namespace mrpt::obs;
20 using namespace mrpt::gui;
21 using namespace mrpt::io;
22 using namespace mrpt::serialization;
23 using namespace mrpt::system;
24 using namespace std;
25 
26 // ------------------------------------------------------
27 // TestCapture_FlyCapture2
28 // ------------------------------------------------------
29 
31 {
32  cout << " FlyCapture2 version: "
34 
35  // Create camera object:
37 
38  // Open camera:
39  TCaptureOptions_FlyCapture2 cam_options;
40 
41  cam_options.framerate = "FRAMERATE_30";
42  cam_options.videomode = "VIDEOMODE_1280x960RGB";
43  // cam_options.videomode="VIDEOMODE_1280x960Y8";
44 
45  capture.open(cam_options);
46 
47  CTicTac tictac;
48  cout << "Press any key to stop capture to 'capture.rawlog'..." << endl;
49 
50  CFileGZOutputStream fil("./capture.rawlog");
51 
52  CDisplayWindow win("Capturing...");
53 
54  int cnt = 0;
55 
57  CObservationImage::Create(); // Memory will be freed
58  // by SF
59  // destructor in each loop.
60 
61  while (!mrpt::system::os::kbhit())
62  {
63  if ((cnt++ % 20) == 0)
64  {
65  if (cnt > 0)
66  {
67  double t = tictac.Tac();
68  double FPS = 20 / t;
69  printf("\n %f FPS\n", FPS);
70  }
71  tictac.Tic();
72  }
73 
74  if (!capture.getObservation(*obs))
75  {
76  cerr << "Error retrieving images!" << endl;
77  break;
78  }
79 
80  cout << ".";
81  cout.flush();
82  if (win.isOpen()) win.showImage(obs->image);
83 
84  archiveFrom(fil) << obs;
85  }
86 }
87 
88 int main(int argc, char** argv)
89 {
90  try
91  {
93  return 0;
94  }
95  catch (const std::exception& e)
96  {
97  std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
98  return -1;
99  }
100  catch (...)
101  {
102  printf("Another exception!!");
103  return -1;
104  }
105 }
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:392
os.h
mrpt::io
Definition: img/CImage.h:24
CImageGrabber_FlyCapture2.h
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:17
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::videomode
std::string videomode
(Default="", which means default) A string with a video mode, from the list available in FlyCapture2:...
Definition: CImageGrabber_FlyCapture2.h:40
mrpt::hwdrivers::CImageGrabber_FlyCapture2::getObservation
bool getObservation(mrpt::obs::CObservationImage &out_observation)
Grab mono image from the camera.
Definition: CImageGrabber_FlyCapture2.cpp:691
mrpt::obs::CObservationImage::Ptr
std::shared_ptr< mrpt::obs ::CObservationImage > Ptr
Definition: CObservationImage.h:34
mrpt::hwdrivers::CImageGrabber_FlyCapture2::open
void open(const TCaptureOptions_FlyCapture2 &options, const bool startCapture=true)
Tries to open the camera with the given options, and starts capture.
Definition: CImageGrabber_FlyCapture2.cpp:267
mrpt::hwdrivers::TCaptureOptions_FlyCapture2
Options used when creating a camera capture object of type CImageGrabber_FlyCapture2.
Definition: CImageGrabber_FlyCapture2.h:18
CFileGZOutputStream.h
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:19
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:86
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
TestCapture_FlyCapture2
void TestCapture_FlyCapture2()
Definition: vision_stereo_rectify/test.cpp:30
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::hwdrivers::TCaptureOptions_FlyCapture2::framerate
std::string framerate
(Default="", which means default) A string with a framerate, from the list available in FlyCapture2::...
Definition: CImageGrabber_FlyCapture2.h:45
argv
const char * argv[]
Definition: RawlogGrabberApp_unittest.cpp:40
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:75
mrpt::gui::CDisplayWindow
This class creates a window as a graphical user interface (GUI) for displaying images to the user.
Definition: CDisplayWindow.h:33
mrpt::serialization
Definition: aligned_serialization.h:13
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
mrpt::hwdrivers::CImageGrabber_FlyCapture2
A wrapper for Point Gray Research (PGR) FlyCapture2 API for capturing images from Firewire,...
Definition: CImageGrabber_FlyCapture2.h:181
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:592
mrpt::hwdrivers::CImageGrabber_FlyCapture2::getFC2version
static std::string getFC2version()
Returns the PGR FlyCapture2 library version.
Definition: CImageGrabber_FlyCapture2.cpp:672
CTicTac.h
argc
const int argc
Definition: RawlogGrabberApp_unittest.cpp:41
CArchive.h
mrpt::exception_to_str
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
CDisplayWindow.h
mrpt::system
Definition: backtrace.h:14



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 23:51:15 UTC 2020