33 #include <visp3/core/vpConfig.h>
34 #include <visp3/core/vpException.h>
35 #include <visp3/core/vpMouseButton.h>
36 #include <visp3/core/vpTime.h>
38 #ifdef VISP_HAVE_DISPLAY
39 #include <visp3/gui/vpPlot.h>
42 #include "vpTutoCommonData.h"
43 #include "vpTutoMeanSquareFitting.h"
44 #include "vpTutoParabolaModel.h"
45 #include "vpTutoSegmentation.h"
47 #ifdef ENABLE_VISP_NAMESPACE
51 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && defined(VISP_HAVE_DISPLAY)
52 int main(
const int argc,
const char *argv[])
54 tutorial::vpTutoCommonData data;
55 int returnCode = data.init(argc, argv);
56 if (returnCode != tutorial::vpTutoCommonData::SOFTWARE_CONTINUE) {
59 tutorial::vpTutoMeanSquareFitting lmsFitter(data.m_degree, data.m_I_orig.getHeight(), data.m_I_orig.getWidth());
60 const unsigned int vertOffset =
static_cast<unsigned int>(data.m_legendOffset.get_i());
61 const unsigned int horOffset =
static_cast<unsigned int>(data.m_ipLegend.get_j());
62 const unsigned int legendLmsVert = data.m_I_orig.getHeight() - 2 * vertOffset;
63 const unsigned int legendLmsHor = horOffset;
66 #ifdef VISP_HAVE_DISPLAY
67 unsigned int plotHeight = 350, plotWidth = 350;
68 int plotXpos =
static_cast<int>(data.m_legendOffset.get_u());
69 int plotYpos =
static_cast<int>(data.m_I_orig.getHeight() + 4. * data.m_legendOffset.get_v());
70 vpPlot plot(1, plotHeight, plotWidth, plotXpos, plotYpos,
"Root mean-square error");
72 plot.setLegend(0, 0,
"LMS estimator");
78 unsigned int nbIter = 0;
79 double meanDtLMS = 0.;
80 double meanRootMeanSquareErrorLMS = 0.;
81 while (!data.m_grabber.end() && run) {
83 std::cout <<
"Iter " << nbIter << std::endl;
84 data.m_grabber.acquire(data.m_I_orig);
87 tutorial::performSegmentationHSV(data);
90 std::vector<vpImagePoint> edgePoints = tutorial::extractSkeleton(data);
93 std::vector<vpImagePoint> noisyEdgePoints = tutorial::addSaltAndPepperNoise(edgePoints, data);
96 #ifdef VISP_HAVE_DISPLAY
106 lmsFitter.fit(noisyEdgePoints);
109 double lmsRootMeanSquareError = lmsFitter.evaluate(edgePoints);
110 std::cout <<
" [Least-Mean Square method] " << std::endl;
111 std::cout <<
" Coeffs = [" << lmsFitter.getCoeffs().transpose() <<
" ]" << std::endl;
112 std::cout <<
" Root Mean Square Error = " << lmsRootMeanSquareError <<
" pixels" << std::endl;
113 std::cout <<
" Fitting duration = " << dtLms <<
" ms" << std::endl;
115 meanRootMeanSquareErrorLMS += lmsRootMeanSquareError;
117 #ifdef VISP_HAVE_DISPLAY
119 lmsFitter.display<
unsigned char>(data.m_IskeletonNoisy,
vpColor::gray, legendLmsVert, legendLmsHor);
122 plot.plot(0, 0, nbIter, lmsRootMeanSquareError);
124 data.displayLegend(data.m_I_orig);
128 run = data.manageClicks(data.m_I_orig, data.m_stepbystep);
133 double iterAsDouble =
static_cast<double>(nbIter);
134 std::cout << std::endl << std::endl <<
"-----[Statistics summary]-----" << std::endl;
135 std::cout <<
" [LMS method] " << std::endl;
136 std::cout <<
" Average Root Mean Square Error = " << meanRootMeanSquareErrorLMS / iterAsDouble <<
" pixels" << std::endl;
137 std::cout <<
" Average fitting duration = " << meanDtLMS / iterAsDouble <<
" ms" << std::endl;
139 #ifdef VISP_HAVE_DISPLAY
140 if (data.m_grabber.end() && (!data.m_stepbystep)) {
143 vpDisplay::displayText(data.m_I_orig, data.m_ipLegend,
"End of sequence reached. Click to exit.", data.m_colorLegend);
157 std::cerr <<
"ViSP must be compiled with C++ standard >= C++11 to use this tutorial." << std::endl;
158 std::cerr <<
"ViSP must also have a 3rd party enabling display features, such as X11 or OpenCV." << std::endl;
static const vpColor gray
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
VISP_EXPORT double measureTimeMs()