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 <mrpt/math/CMatrix.h>
14 #include <iostream>
15 
16 using namespace mrpt;
17 using namespace mrpt::gui;
18 using namespace mrpt::img;
19 using namespace mrpt::math;
20 using namespace mrpt::system;
21 using namespace std;
22 
23 #include <mrpt/examples_config.h>
24 string myDataDir(MRPT_EXAMPLES_BASE_DIRECTORY + string("img_basic_example/"));
25 
26 // ------------------------------------------------------
27 // TestImageCap
28 // ------------------------------------------------------
30 {
31  // BMP -> JPEG conversion tester:
32  // --------------------------------
33  CImage img, img2;
34  CTicTac tictac;
35  CTimeLogger timlog;
36 
37  tictac.Tic();
38  if (!img.loadFromFile(myDataDir + string("frame_color.jpg")))
39  {
40  cerr << "Cannot load " << myDataDir + string("frame_color.jpg") << endl;
41  return;
42  }
43  printf("Image loaded in %.03fms\n", 1000 * tictac.Tac());
44 
45  if (false) // A very simple test:
46  {
47  CDisplayWindow win1("JPEG file, color");
48  win1.setPos(10, 10);
49 
50  win1.showImage(img);
51 
52  cout << "Push a key in the console or in the window to continue...";
53  win1.waitForKey();
54  cout << "Done" << endl;
55 
56  timlog.enter("grayscale1");
57  img = img.grayscale();
58  timlog.leave("grayscale1");
59 
60  CDisplayWindow win2("JPEG file, gray");
61  win2.showImage(img);
62  win1.setPos(300, 10);
63 
64  cout << "Push a key in the console or in the window to continue...";
65  win2.waitForKey();
66  cout << "Done" << endl;
67 
69  return;
70  }
71 
72  CDisplayWindow win1("win1"), win2("win2"), win3("win3"), win4("win4");
73 
74  CImage imgSmall(img);
75  CImage imgGray;
76 
77  for (int i = 0; i < 50; i++)
78  {
79  timlog.enter("grayscale2");
80  imgSmall.grayscale(imgGray);
81  timlog.leave("grayscale2");
82  }
83 
84  CImage imgSmall2(imgGray.scaleHalfSmooth());
85  CImage imgSmallRGB(img.scaleHalf()); // Smooth() );
86 
87  // Test some draw capabilities:
88  // ---------------------------------
89  imgSmall.rectangle(85, 35, 170, 170, TColor(255, 0, 0), 10);
90 
91  imgSmall.line(550, 75, 650, 25, TColor(0, 0, 255));
92  imgSmall.line(-10, -20, 20, 30, TColor(0, 0, 255));
93 
94  CMatrix COV(2, 2);
95  COV(0, 0) = 100;
96  COV(1, 1) = 50;
97  COV(0, 1) = COV(1, 0) = -30;
98  imgSmall.ellipseGaussian(&COV, 600.0f, 50.0f, 2, TColor(255, 255, 0), 4);
99  imgGray.ellipseGaussian(&COV, 100.0f, 100.0f, 2, TColor(0, 0, 255), 4);
100 
101  imgSmall.drawImage(400, 500, imgGray);
102 
103  // Show the windows now:
104  // ------------------------------------------------------
105  win1.showImage(imgSmall);
106  win1.setPos(0, 0);
107  win2.showImage(imgSmall2);
108  win2.setPos(810, 0);
109  win3.showImage(imgGray);
110  win3.setPos(810, 300);
111  win4.showImage(imgSmallRGB);
112  win4.setPos(300, 400);
113 
114  cout << "Press any key on 'win4' to exit" << endl;
115  win4.waitForKey();
116 
117  tictac.Tic();
118  img2.saveToFile("frame_out.jpg");
119  printf("jpeg file saved in %.03fms\n", 1000.0f * tictac.Tac());
120 
121  imgSmall2.saveToFile("frame_out_small.png");
122 
123  return;
124 }
125 
126 // ------------------------------------------------------
127 // MAIN
128 // ------------------------------------------------------
129 int main()
130 {
131  try
132  {
134  return 0;
135  }
136  catch (std::exception& e)
137  {
138  std::cout << "MRPT exception caught: " << e.what() << std::endl;
139  return -1;
140  }
141  catch (...)
142  {
143  printf("Untyped exception!!");
144  return -1;
145  }
146 }
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
mrpt::img::CImage::scaleHalfSmooth
CImage scaleHalfSmooth() const
Returns a new image scaled down to half its original size (averaging between every two rows)
Definition: img/CImage.h:363
mrpt::system::CTimeLogger
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X),...
Definition: system/CTimeLogger.h:43
CMatrix.h
myDataDir
std::string myDataDir
Definition: vision_stereo_rectify/test.cpp:23
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::CTimeLogger::enter
void enter(const char *func_name)
Start of a named section.
Definition: system/CTimeLogger.h:116
mrpt::img::CCanvas::ellipseGaussian
void ellipseGaussian(const MATRIX2X2 *cov2D, const double mean_x, const double mean_y, double confIntervalStds=2, const mrpt::img::TColor &color=mrpt::img::TColor(255, 255, 255), unsigned int width=1, int nEllipsePoints=20)
Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution.
Definition: CCanvas.h:252
mrpt::system::CTimeLogger::leave
double leave(const char *func_name)
End of a named section.
Definition: system/CTimeLogger.h:122
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::math::CMatrix
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
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
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
mrpt::img::CImage::saveToFile
bool saveToFile(const std::string &fileName, int jpeg_quality=95) const
Save the image to a file, whose format is determined from the extension (internally uses OpenCV).
Definition: CImage.cpp:296
img
GLint GLvoid * img
Definition: glext.h:3763
CTicTac.h
CTimeLogger.h
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
string
GLsizei const GLchar ** string
Definition: glext.h:4101
TestImageConversion
void TestImageConversion()
Definition: vision_stereo_rectify/test.cpp:29
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