Go to the documentation of this file.
42 const size_t N_PLANES = 3;
44 const size_t N_plane = 300;
45 const size_t N_noise = 300;
47 const double PLANE_EQ[N_PLANES][4] = {
48 {1, -1, 1, -2}, {1, +1.5, 1, -1}, {0, -1, 1, +2}};
51 for (
size_t p = 0;
p < N_PLANES;
p++)
53 for (
size_t i = 0; i < N_plane; i++)
60 -(PLANE_EQ[
p][3] + PLANE_EQ[
p][0] * xx + PLANE_EQ[
p][1] * yy) /
68 for (
size_t i = 0; i < N_noise; i++)
77 vector<pair<size_t, TPlane>> detectedPlanes;
78 const double DIST_THRESHOLD = 0.05;
85 cout <<
"RANSAC method: ransac_detect_3D_planes" << endl;
86 cout <<
" Computation time: " << tictac.
Tac() * 1000.0 <<
" ms" << endl;
87 cout <<
" " << detectedPlanes.size() <<
" planes detected." << endl;
95 mrpt::make_aligned_shared<opengl::COpenGLScene>();
98 mrpt::make_aligned_shared<opengl::CGridPlaneXY>(
99 -20, 20, -20, 20, 0, 1));
102 for (vector<pair<size_t, TPlane>>::
iterator p = detectedPlanes.begin();
103 p != detectedPlanes.end(); ++
p)
106 mrpt::make_aligned_shared<opengl::CTexturedPlane>(-10, 10, -10, 10);
109 p->second.getAsPose3D(glPlanePose);
110 glPlane->setPose(glPlanePose);
117 scene->insert(glPlane);
122 mrpt::make_aligned_shared<opengl::CPointCloud>();
123 points->setColor(0, 0, 1);
125 points->enableColorFromZ();
128 vector<float> xsf, ysf, zsf;
133 points->setAllPoints(xsf, ysf, zsf);
138 win->get3DSceneAndLock() = scene;
139 win->unlockAccess3DScene();
154 const size_t N_LINES = 4;
156 const size_t N_line = 30;
157 const size_t N_noise = 50;
159 const double LINE_EQ[N_LINES][3] = {
160 {1, -1, -2}, {1, +1.5, -1}, {0, -1, +2}, {0.5, -0.3, +1}};
163 for (
size_t p = 0;
p < N_LINES;
p++)
165 for (
size_t i = 0; i < N_line; i++)
170 (LINE_EQ[
p][2] + LINE_EQ[
p][0] * xx) / LINE_EQ[
p][1];
176 for (
size_t i = 0; i < N_noise; i++)
184 vector<pair<size_t, TLine2D>> detectedLines;
185 const double DIST_THRESHOLD = 0.2;
192 cout <<
"RANSAC method: ransac_detect_2D_lines" << endl;
193 cout <<
" Computation time: " << tictac.
Tac() * 1000.0 <<
" ms" << endl;
194 cout <<
" " << detectedLines.size() <<
" lines detected." << endl;
200 win2.plot(xs, ys,
".b4",
"points");
203 for (vector<pair<size_t, TLine2D>>::
iterator p = detectedLines.begin();
204 p != detectedLines.end(); ++
p)
209 for (CVectorDouble::Index
q = 0;
q < lx.size();
q++)
210 ly[
q] = -(
p->second.coefs[2] +
p->second.coefs[0] * lx[
q]) /
212 win2.plot(lx, ly,
"r-1",
format(
"line_%u",
n++));
229 cout << endl <<
"Now running detection of lines..." << endl << endl;
236 catch (std::exception& e)
238 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
243 printf(
"Untyped exception!!");
void copy_container_typecasting(const src_container &src, dst_container &trg)
Copy all the elements in a container (vector, deque, list) into a different one performing the approp...
GLdouble GLdouble GLdouble GLdouble q
A high-performance stopwatch, with typical resolution of nanoseconds.
std::shared_ptr< CTexturedPlane > Ptr
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
GLsizei const GLfloat * points
void ransac_detect_2D_lines(const Eigen::Matrix< NUMTYPE, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< NUMTYPE, Eigen::Dynamic, 1 > &y, std::vector< std::pair< size_t, TLine2D >> &out_detected_lines, const double threshold, const size_t min_inliers_for_valid_line=5)
Fit a number of 2-D lines to a given point cloud, automatically determining the number of existing li...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
std::shared_ptr< CPointCloud > Ptr
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
double Tac() noexcept
Stops the stopwatch.
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm,...
mrpt::gui::CDisplayWindow3D::Ptr win
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::shared_ptr< CDisplayWindow3D > Ptr
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Classes for creating GUI windows for 2D and 3D visualization.
Create a GUI window and display plots with MATLAB-like interfaces and commands.
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
This base provides a set of functions for maths stuff.
std::shared_ptr< COpenGLScene > Ptr
A namespace of pseudo-random numbers generators of diferent distributions.
double drawGaussian1D(const double mean, const double std)
Generate a normally distributed pseudo-random number.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
void ransac_detect_3D_planes(const Eigen::Matrix< NUMTYPE, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< NUMTYPE, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< NUMTYPE, Eigen::Dynamic, 1 > &z, std::vector< std::pair< size_t, TPlane >> &out_detected_planes, const double threshold, const size_t min_inliers_for_valid_plane=10)
Fit a number of 3-D planes to a given point cloud, automatically determining the number of existing p...
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 | |