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>
13 #include <iostream>
14 
15 using namespace mrpt::gui;
16 using namespace mrpt::hwdrivers;
17 using namespace mrpt::system;
18 using namespace mrpt::img;
19 using namespace std;
20 
21 // ------------------------------------------------------
22 // Test_FFMPEG_CaptureCamera
23 // ------------------------------------------------------
24 void Test_FFMPEG_CaptureCamera(const std::string& video_url)
25 {
26  CFFMPEG_InputStream in_video;
27 
28  if (!in_video.openURL(video_url, false /*grayscale*/, true /* verbose */))
29  return;
30 
31  CDisplayWindow win("Video");
32 
33  CTicTac tictac;
34  tictac.Tic();
35  unsigned int nFrames = 0;
36 
37  CImage img;
38  while (win.isOpen() && in_video.retrieveFrame(img))
39  {
40  double fps = ++nFrames / tictac.Tac();
41  img.textOut(
42  5, 5, mrpt::format("%.02f fps", fps), TColor(0x80, 0x80, 0x80));
43  if (nFrames > 100)
44  {
45  tictac.Tic();
46  nFrames = 0;
47  }
48 
49  if (nFrames == 1)
50  cout << "Video FPS: " << in_video.getVideoFPS() << endl;
51 
52  win.showImage(img);
53  std::this_thread::sleep_for(10ms);
54 
55  if (win.keyHit() && win.waitForKey() == 27) break;
56  }
57 
58  in_video.close();
60 }
61 
62 int main(int argc, char** argv)
63 {
64  try
65  {
66  if (argc != 2)
67  {
68  cout << "Usage: " << endl;
69  cout << " Open a video file: " << argv[0] << " <VIDEOFILE>" << endl;
70  cout << " Open an IP camera: " << argv[0]
71  << " rtsp://a.b.c.d/live.sdp" << endl;
72  cout << endl;
73  return 1;
74  }
75 
77 
78  return 0;
79  }
80  catch (std::exception& e)
81  {
82  std::cout << "MRPT exception caught: " << e.what() << std::endl;
83  return -1;
84  }
85  catch (...)
86  {
87  printf("Another exception!!");
88  return -1;
89  }
90 }
Test_FFMPEG_CaptureCamera
void Test_FFMPEG_CaptureCamera(const std::string &video_url)
Definition: vision_stereo_rectify/test.cpp:24
mrpt::hwdrivers::CFFMPEG_InputStream::close
void close()
Close the video stream (this is called automatically at destruction).
Definition: CFFMPEG_InputStream.cpp:283
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
mrpt::hwdrivers::CFFMPEG_InputStream
A generic class which process a video file or other kind of input stream (http, rtsp) and allows the ...
Definition: CFFMPEG_InputStream.h:42
mrpt::hwdrivers::CFFMPEG_InputStream::retrieveFrame
bool retrieveFrame(mrpt::img::CImage &out_img)
Get the next frame from the video stream.
Definition: CFFMPEG_InputStream.cpp:342
mrpt::hwdrivers::CFFMPEG_InputStream::getVideoFPS
double getVideoFPS() const
Get the frame-per-second (FPS) of the video source, or "-1" if the video is not open.
Definition: CFFMPEG_InputStream.cpp:433
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:22
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::img
Definition: CCanvas.h:17
mrpt::hwdrivers::CFFMPEG_InputStream::openURL
bool openURL(const std::string &url, bool grab_as_grayscale=false, bool verbose=false)
Open a video file or a video stream (rtsp://) This can be used to open local video files (eg.
Definition: CFFMPEG_InputStream.cpp:118
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
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
CFFMPEG_InputStream.h
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
img
GLint GLvoid * img
Definition: glext.h:3763
CTicTac.h
string
GLsizei const GLchar ** string
Definition: glext.h:4101
CDisplayWindow.h
mrpt::system::pause
void pause(const std::string &msg=std::string("Press any key to continue...")) noexcept
Shows the message "Press any key to continue" (or other custom message) to the current standard outpu...
Definition: os.cpp:428
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