1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2021, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */
#include <mrpt/gui/CDisplayWindow.h>
#include <mrpt/hwdrivers/CFFMPEG_InputStream.h>
#include <mrpt/system/CTicTac.h>
#include <iostream>
using namespace mrpt::gui;
using namespace mrpt::hwdrivers;
using namespace mrpt::system;
using namespace mrpt::img;
using namespace std;
// ------------------------------------------------------
// Test_FFMPEG_CaptureCamera
// ------------------------------------------------------
void Test_FFMPEG_CaptureCamera(const std::string& video_url)
{
CFFMPEG_InputStream in_video;
if (!in_video.openURL(video_url, false /*grayscale*/, true /* verbose */))
return;
CDisplayWindow win("Video");
CTicTac tictac;
tictac.Tic();
unsigned int nFrames = 0;
CImage img;
while (win.isOpen() && in_video.retrieveFrame(img))
{
double fps = ++nFrames / tictac.Tac();
img.textOut(
5, 5, mrpt::format("%.02f fps", fps), TColor(0x80, 0x80, 0x80));
if (nFrames > 100)
{
tictac.Tic();
nFrames = 0;
}
if (nFrames == 1)
cout << "Video FPS: " << in_video.getVideoFPS() << endl;
win.showImage(img);
std::this_thread::sleep_for(10ms);
if (win.keyHit() && win.waitForKey() == 27) break;
}
in_video.close();
mrpt::system::pause();
}
int main(int argc, char** argv)
{
try
{
if (argc != 2)
{
cout << "Usage: " << endl;
cout << " Open a video file: " << argv[0] << " <VIDEOFILE>" << endl;
cout << " Open an IP camera: " << argv[0]
<< " rtsp://a.b.c.d/live.sdp" << endl;
cout << endl;
return 1;
}
Test_FFMPEG_CaptureCamera(argv[1]);
return 0;
}
catch (const std::exception& e)
{
std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
return -1;
}
catch (...)
{
printf("Another exception!!");
return -1;
}
}
|