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 <mrpt/system/os.h>
17 #include <iostream>
18 
19 using namespace mrpt::hwdrivers;
20 using namespace mrpt::gui;
21 using namespace mrpt::obs;
22 using namespace mrpt::io;
23 using namespace mrpt::system;
24 using namespace mrpt::serialization;
25 using namespace std;
26 
27 // ------------------------------------------------------
28 // TestCapture_FlyCapture2_stereo
29 // ------------------------------------------------------
30 
32 {
33  cout << " FlyCapture2 version: "
35 
36  // Left camera:
37  // ------------------------------------------
38  CImageGrabber_FlyCapture2 capture_left;
39  TCaptureOptions_FlyCapture2 cam_options_left;
40 
41  cam_options_left.framerate = "FRAMERATE_30";
42  cam_options_left.videomode = "VIDEOMODE_1280x960RGB";
43 
44  cam_options_left.open_by_guid = true;
45  cam_options_left.camera_guid[0] = 0x63A8D3CE;
46  cam_options_left.camera_guid[1] = 0xB49580D6;
47  cam_options_left.camera_guid[2] = 0x004AED1C;
48  cam_options_left.camera_guid[3] = 0xDDE4EF14;
49 
50  cam_options_left.strobe_enabled = true;
51  cam_options_left.strobe_source = 1; // GPIO pin #
52  cam_options_left.strobe_duration = 1.0; // ms
53 
54  capture_left.open(
55  cam_options_left, false /*only open, don't start grabbing*/);
56 
57  // Right camera:
58  // ------------------------------------------
59  CImageGrabber_FlyCapture2 capture_right;
60  TCaptureOptions_FlyCapture2 cam_options_right;
61 
62  cam_options_right.framerate = cam_options_left.framerate;
63  cam_options_right.videomode = cam_options_left.videomode;
64 
65  cam_options_right.open_by_guid = true;
66  cam_options_right.camera_guid[0] = 0xB9862FD2;
67  cam_options_right.camera_guid[1] = 0x7AE0E03A;
68  cam_options_right.camera_guid[2] = 0xA6BC0321;
69  cam_options_right.camera_guid[3] = 0x16654DC9;
70 
71  cam_options_right.trigger_enabled = true;
72  cam_options_right.trigger_source = 0; // GPIO pin #
73 
74  capture_right.open(
75  cam_options_right, false /*only open, don't start grabbing*/);
76 
77 // Open both cameras simultaneously:
78 #if 0
79  const CImageGrabber_FlyCapture2 *cameras[2] = { &capture_left, &capture_right };
80  CImageGrabber_FlyCapture2::startSyncCapture(2 /*numCameras*/, cameras);
81 #else
82  capture_right.startCapture(); // Will not start until a strobe is got from
83  // the "master" camera:
84  capture_left.startCapture();
85 #endif
86 
87  CTicTac tictac;
88  cout << "Press any key to stop capture to 'capture.rawlog'..." << endl;
89 
90  CFileGZOutputStream fil("./capture.rawlog");
91 
92  CDisplayWindow winL("Left"), winR("Right");
93 
94  int cnt = 0;
95 
97  mrpt::make_aligned_shared<CObservationImage>(); // Memory will be freed
98  // by SF
99  // destructor in each loop.
100  obsL->sensorLabel = "LEFT";
101 
103  mrpt::make_aligned_shared<CObservationImage>(); // Memory will be freed
104  // by SF
105  // destructor in each loop.
106  obsR->sensorLabel = "RIGHT";
107 
108  while (!mrpt::system::os::kbhit())
109  {
110  if ((cnt++ % 20) == 0)
111  {
112  if (cnt > 0)
113  {
114  double t = tictac.Tac();
115  double FPS = 20 / t;
116  printf("\n %f FPS\n", FPS);
117  }
118  tictac.Tic();
119  }
120 
121  const bool ok1 = capture_left.getObservation(*obsL);
122  const bool ok2 = capture_right.getObservation(*obsR);
123  if (!ok1 || !ok2)
124  {
125  cerr << "Error retrieving images!" << endl;
126  break;
127  }
128 
129  cout << ".";
130  cout.flush();
131  if (winL.isOpen()) winL.showImage(obsL->image);
132  if (winR.isOpen()) winR.showImage(obsR->image);
133 
134  archiveFrom(fil) << obsL << obsR;
135  }
136 }
137 
138 int main(int argc, char** argv)
139 {
140  try
141  {
143  return 0;
144  }
145  catch (std::exception& e)
146  {
147  std::cout << "MRPT exception caught: " << e.what() << std::endl;
148  return -1;
149  }
150  catch (...)
151  {
152  printf("Another exception!!");
153  return -1;
154  }
155 }
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
os.h
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::strobe_source
unsigned int strobe_source
(default=0) Refer to PGR docs.
Definition: CImageGrabber_FlyCapture2.h:76
mrpt::io
Definition: img/CImage.h:22
CImageGrabber_FlyCapture2.h
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
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:43
mrpt::hwdrivers::CImageGrabber_FlyCapture2::getObservation
bool getObservation(mrpt::obs::CObservationImage &out_observation)
Grab mono image from the camera.
Definition: CImageGrabber_FlyCapture2.cpp:726
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:299
mrpt::hwdrivers::TCaptureOptions_FlyCapture2
Options used when creating a camera capture object of type CImageGrabber_FlyCapture2.
Definition: CImageGrabber_FlyCapture2.h:21
CFileGZOutputStream.h
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:22
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::trigger_source
unsigned int trigger_source
(default=0) Refer to PGR docs.
Definition: CImageGrabber_FlyCapture2.h:68
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::open_by_guid
bool open_by_guid
(Default=false) Set to true to force opening a camera by its GUID, in camera_guid
Definition: CImageGrabber_FlyCapture2.h:32
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
mrpt::hwdrivers::CImageGrabber_FlyCapture2::startCapture
void startCapture()
Start the actual image capture of the camera.
Definition: CImageGrabber_FlyCapture2.cpp:584
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::camera_guid
unsigned int camera_guid[4]
GUID of the camera to open, only when open_by_guid==true.
Definition: CImageGrabber_FlyCapture2.h:34
TestCapture_FlyCapture2_stereo
void TestCapture_FlyCapture2_stereo()
Definition: vision_stereo_rectify/test.cpp:31
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
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::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:48
mrpt::hwdrivers::CImageGrabber_FlyCapture2::startSyncCapture
static void startSyncCapture(int numCameras, const CImageGrabber_FlyCapture2 **cameras_array)
Starts a synchronous capture of several cameras, which must have been already opened.
Definition: CImageGrabber_FlyCapture2.cpp:602
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::strobe_enabled
bool strobe_enabled
(default=false) Enable the generation of a strobe signal in GPIO.
Definition: CImageGrabber_FlyCapture2.h:74
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::serialization
Definition: aligned_serialization.h:14
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::hwdrivers::CImageGrabber_FlyCapture2
A wrapper for Point Gray Research (PGR) FlyCapture2 API for capturing images from Firewire,...
Definition: CImageGrabber_FlyCapture2.h:187
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
mrpt::hwdrivers::CImageGrabber_FlyCapture2::getFC2version
static std::string getFC2version()
Returns the PGR FlyCapture2 library version.
Definition: CImageGrabber_FlyCapture2.cpp:707
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::trigger_enabled
bool trigger_enabled
(default=false) Enable non-free-running mode, only capturing when a given input trigger signal is det...
Definition: CImageGrabber_FlyCapture2.h:64
CTicTac.h
mrpt::hwdrivers::TCaptureOptions_FlyCapture2::strobe_duration
float strobe_duration
(default=1.0) Pulse durationin ms.
Definition: CImageGrabber_FlyCapture2.h:82
CObservationImage.h
CArchive.h
CDisplayWindow.h
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