diff --git a/modules/imgproc/src/vpCircleHoughTransform_common.cpp b/modules/imgproc/src/vpCircleHoughTransform_common.cpp index 11114df4e0..20135a0574 100644 --- a/modules/imgproc/src/vpCircleHoughTransform_common.cpp +++ b/modules/imgproc/src/vpCircleHoughTransform_common.cpp @@ -91,6 +91,7 @@ vpCircleHoughTransform::~vpCircleHoughTransform() using json = nlohmann::json; vpCircleHoughTransform::vpCircleHoughTransform(const std::string &jsonPath) + : mp_mask(nullptr) { initFromJSON(jsonPath); } @@ -413,6 +414,7 @@ std::ostream & operator<<(std::ostream &os, const vpCircleHoughTransform &detector) { os << detector.toString(); + std::cout << "\tUse mask: " << (detector.mp_mask == nullptr ? "false" : "true") << std::endl; return os; } diff --git a/tutorial/imgproc/hough-transform/drawingHelpers.cpp b/tutorial/imgproc/hough-transform/drawingHelpers.cpp index d443cf7815..322f8ca071 100644 --- a/tutorial/imgproc/hough-transform/drawingHelpers.cpp +++ b/tutorial/imgproc/hough-transform/drawingHelpers.cpp @@ -8,38 +8,14 @@ using namespace VISP_NAMESPACE_NAME; #endif -#if defined(VISP_HAVE_X11) -vpDisplayX drawingHelpers::d; -#elif defined(VISP_HAVE_OPENCV) -vpDisplayOpenCV drawingHelpers::d; -#elif defined(VISP_HAVE_GTK) -vpDisplayGTK drawingHelpers::d; -#elif defined(VISP_HAVE_GDI) -vpDisplayGDI drawingHelpers::d; -#elif defined(VISP_HAVE_D3D9) -vpDisplayD3D drawingHelpers::d; -#endif - -vpImage drawingHelpers::I_disp; - bool drawingHelpers::display(vpImage< vpRGBa> &I, const std::string &title, const bool &blockingMode) { - I_disp = I; -#if defined(VISP_HAVE_DISPLAY) - if (!d.isInitialised()) { - d.init(I_disp); - vpDisplay::setTitle(I_disp, title); - } -#else - (void)title; -#endif - - vpDisplay::display(I_disp); - vpDisplay::displayText(I_disp, 15, 15, "Left click to continue...", vpColor::red); - vpDisplay::displayText(I_disp, 35, 15, "Right click to stop...", vpColor::red); - vpDisplay::flush(I_disp); + vpDisplay::display(I); + vpDisplay::displayText(I, 15, 15, "Left click to continue...", vpColor::red); + vpDisplay::displayText(I, 35, 15, "Right click to stop...", vpColor::red); + vpDisplay::flush(I); vpMouseButton::vpMouseButtonType button; - vpDisplay::getClick(I_disp, button, blockingMode); + vpDisplay::getClick(I, button, blockingMode); bool hasToContinue = true; if (button == vpMouseButton::button3) { // Right click => stop the program @@ -49,18 +25,18 @@ bool drawingHelpers::display(vpImage< vpRGBa> &I, const std::string &title, cons return hasToContinue; } -bool drawingHelpers::display(vpImage &D, const std::string &title, const bool &blockingMode) +bool drawingHelpers::display(vpImage &D, vpImage &Idisp, const std::string &title, const bool &blockingMode) { - vpImage I; // Image to display - vpImageConvert::convert(D, I); - return display(I, title, blockingMode); + vpImageConvert::convert(D, Idisp); + return display(Idisp, title, blockingMode); } -bool drawingHelpers::display(vpImage &D, const std::string &title, const bool &blockingMode) +bool drawingHelpers::display(vpImage &D, vpImage &Idisp, const std::string &title, const bool &blockingMode) { vpImage I; // Image to display vpImageConvert::convert(D, I); - return display(I, title, blockingMode); + vpImageConvert::convert(I, Idisp); + return display(Idisp, title, blockingMode); } #endif diff --git a/tutorial/imgproc/hough-transform/drawingHelpers.h b/tutorial/imgproc/hough-transform/drawingHelpers.h index 1837aef600..ab9045c820 100644 --- a/tutorial/imgproc/hough-transform/drawingHelpers.h +++ b/tutorial/imgproc/hough-transform/drawingHelpers.h @@ -2,31 +2,16 @@ #define DRAWING_HELPERS_H #include +#include #include -#include -#include -#include +#include #ifndef DOXYGEN_SHOULD_SKIP_THIS namespace drawingHelpers { -#if defined(VISP_HAVE_X11) -extern VISP_NAMESPACE_ADDRESSING vpDisplayX d; -#elif defined(VISP_HAVE_OPENCV) -extern VISP_NAMESPACE_ADDRESSING vpDisplayOpenCV d; -#elif defined(VISP_HAVE_GTK) -extern VISP_NAMESPACE_ADDRESSING vpDisplayGTK d; -#elif defined(VISP_HAVE_GDI) -extern VISP_NAMESPACE_ADDRESSING vpDisplayGDI d; -#elif defined(VISP_HAVE_D3D9) -extern VISP_NAMESPACE_ADDRESSING vpDisplayD3D d; -#endif - -extern VISP_NAMESPACE_ADDRESSING vpImage I_disp; - bool display(VISP_NAMESPACE_ADDRESSING vpImage &I, const std::string &title, const bool &blockingMode); -bool display(VISP_NAMESPACE_ADDRESSING vpImage &I, const std::string &title, const bool &blockingMode); -bool display(VISP_NAMESPACE_ADDRESSING vpImage &D, const std::string &title, const bool &blockingMode); +bool display(VISP_NAMESPACE_ADDRESSING vpImage &I, VISP_NAMESPACE_ADDRESSING vpImage &Idisp, const std::string &title, const bool &blockingMode); +bool display(VISP_NAMESPACE_ADDRESSING vpImage &D, VISP_NAMESPACE_ADDRESSING vpImage &Idisp, const std::string &title, const bool &blockingMode); } #endif diff --git a/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp b/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp index 5b0081a491..04742e05c7 100644 --- a/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp +++ b/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,7 @@ using namespace VISP_NAMESPACE_NAME; #endif -bool run_detection(const vpImage &I_src, vpCircleHoughTransform &detector, const int &nbCirclesToDetect, const bool &blockingMode, const bool &displayCanny) +bool run_detection(const vpImage &I_src, vpImage &I_disp, vpImage &I_dispCanny, vpCircleHoughTransform &detector, const int &nbCirclesToDetect, const bool &blockingMode, const bool &displayCanny) { double t0 = vpTime::measureTimeMicros(); //! [Run detection] @@ -30,7 +31,6 @@ bool run_detection(const vpImage &I_src, vpCircleHoughTransform & //! [Run detection] double tF = vpTime::measureTimeMicros(); std::cout << "Process time = " << (tF - t0) * 0.001 << "ms" << std::endl << std::flush; - vpImage I_disp; vpImageConvert::convert(I_src, I_disp); unsigned int id = 0; @@ -115,7 +115,7 @@ bool run_detection(const vpImage &I_src, vpCircleHoughTransform & if (displayCanny) { vpImage edgeMap = detector.getEdgeMap(); - drawingHelpers::display(edgeMap, "Edge map", true); + drawingHelpers::display(edgeMap, I_dispCanny, "Edge map", blockingMode); } return drawingHelpers::display(I_disp, "Detection results", blockingMode); } @@ -511,7 +511,39 @@ int main(int argc, char **argv) //! [Algo init] std::cout << detector; + //! [Display init] vpImage I_src; + vpImage I_disp; + vpImage I_dispCanny; + // Read the (first) image + char *filename = new char[opt_input.size() + 50]; + if (opt_input.find("%") != std::string::npos) { + // Read the first frame + sprintf(filename, opt_input.c_str(), 0); + } + else { + // Simply get the filename + strcpy(filename, opt_input.c_str()); + } + std::string filenameAsStr(filename); + delete[] filename; + vpImageIo::read(I_src, filenameAsStr); + I_disp.resize(I_src.getHeight(), I_src.getWidth()); + I_dispCanny.resize(I_src.getHeight(), I_src.getWidth()); +#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) + std::shared_ptr dColor = vpDisplayFactory::createDisplay(I_disp, -1, -1, "Input image");; + std::shared_ptr dCanny(nullptr); + if (opt_displayCanny) { + dCanny = vpDisplayFactory::createDisplay(I_dispCanny, I_src.getWidth() + 40, -1, "Edge-map"); + } +#else + vpDisplay *dColor = vpDisplayFactory::allocateDisplay(I_disp, -1, -1, "Input image");; + vpDisplay *dCanny(nullptr); + if (opt_displayCanny) { + dCanny = vpDisplayFactory::allocateDisplay(I_dispCanny, I_src.getWidth() + 40, -1, "Edge-map"); + } +#endif + //! [Display init] //! [Manage video] if (opt_input.find("%") != std::string::npos) { @@ -522,7 +554,7 @@ int main(int argc, char **argv) g.open(I_src); while (!g.end() && hasToContinue) { g.acquire(I_src); - hasToContinue = run_detection(I_src, detector, opt_nbCirclesToDetect, false, opt_displayCanny); + hasToContinue = run_detection(I_src, I_disp, I_dispCanny, detector, opt_nbCirclesToDetect, false, opt_displayCanny); vpTime::wait(40); } } @@ -535,9 +567,15 @@ int main(int argc, char **argv) } // Read the image and perform detection on it vpImageIo::read(I_src, opt_input); - run_detection(I_src, detector, opt_nbCirclesToDetect, true, opt_displayCanny); + run_detection(I_src, I_disp, I_dispCanny, detector, opt_nbCirclesToDetect, true, opt_displayCanny); //! [Manage single image] } +#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) + delete dColor; + if (dCanny != nullptr) { + delete dCanny; + } +#endif return EXIT_SUCCESS; }