Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circle Hough Transform improvements #1499

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/imgproc/src/vpCircleHoughTransform_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
using json = nlohmann::json;

vpCircleHoughTransform::vpCircleHoughTransform(const std::string &jsonPath)
: mp_mask(nullptr)

Check warning on line 94 in modules/imgproc/src/vpCircleHoughTransform_common.cpp

View check run for this annotation

Codecov / codecov/patch

modules/imgproc/src/vpCircleHoughTransform_common.cpp#L94

Added line #L94 was not covered by tests
{
initFromJSON(jsonPath);
}
Expand Down Expand Up @@ -413,6 +414,7 @@
operator<<(std::ostream &os, const vpCircleHoughTransform &detector)
{
os << detector.toString();
std::cout << "\tUse mask: " << (detector.mp_mask == nullptr ? "false" : "true") << std::endl;

Check warning on line 417 in modules/imgproc/src/vpCircleHoughTransform_common.cpp

View check run for this annotation

Codecov / codecov/patch

modules/imgproc/src/vpCircleHoughTransform_common.cpp#L417

Added line #L417 was not covered by tests
return os;
}

Expand Down
46 changes: 11 additions & 35 deletions tutorial/imgproc/hough-transform/drawingHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<vpRGBa> 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
Expand All @@ -49,18 +25,18 @@ bool drawingHelpers::display(vpImage< vpRGBa> &I, const std::string &title, cons
return hasToContinue;
}

bool drawingHelpers::display(vpImage<unsigned char> &D, const std::string &title, const bool &blockingMode)
bool drawingHelpers::display(vpImage<unsigned char> &D, vpImage<vpRGBa> &Idisp, const std::string &title, const bool &blockingMode)
{
vpImage<vpRGBa> 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<double> &D, const std::string &title, const bool &blockingMode)
bool drawingHelpers::display(vpImage<double> &D, vpImage<vpRGBa> &Idisp, const std::string &title, const bool &blockingMode)
{
vpImage<unsigned char> I; // Image to display
vpImageConvert::convert(D, I);
return display(I, title, blockingMode);
vpImageConvert::convert(I, Idisp);
return display(Idisp, title, blockingMode);
}

#endif
23 changes: 4 additions & 19 deletions tutorial/imgproc/hough-transform/drawingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,16 @@
#define DRAWING_HELPERS_H

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpDisplay.h>
#include <visp3/core/vpImage.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/core/vpImageConvert.h>

#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<VISP_NAMESPACE_ADDRESSING vpRGBa> I_disp;

bool display(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I, const std::string &title, const bool &blockingMode);
bool display(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, const std::string &title, const bool &blockingMode);
bool display(VISP_NAMESPACE_ADDRESSING vpImage<double> &D, const std::string &title, const bool &blockingMode);
bool display(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &Idisp, const std::string &title, const bool &blockingMode);
bool display(VISP_NAMESPACE_ADDRESSING vpImage<double> &D, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &Idisp, const std::string &title, const bool &blockingMode);
}

#endif
Expand Down
48 changes: 43 additions & 5 deletions tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <visp3/core/vpImageDraw.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/imgproc/vpCircleHoughTransform.h>
#include <visp3/imgproc/vpImgproc.h>
#include <visp3/io/vpImageIo.h>
Expand All @@ -21,7 +22,7 @@
using namespace VISP_NAMESPACE_NAME;
#endif

bool run_detection(const vpImage<unsigned char> &I_src, vpCircleHoughTransform &detector, const int &nbCirclesToDetect, const bool &blockingMode, const bool &displayCanny)
bool run_detection(const vpImage<unsigned char> &I_src, vpImage<vpRGBa> &I_disp, vpImage<vpRGBa> &I_dispCanny, vpCircleHoughTransform &detector, const int &nbCirclesToDetect, const bool &blockingMode, const bool &displayCanny)
{
double t0 = vpTime::measureTimeMicros();
//! [Run detection]
Expand All @@ -30,7 +31,6 @@ bool run_detection(const vpImage<unsigned char> &I_src, vpCircleHoughTransform &
//! [Run detection]
double tF = vpTime::measureTimeMicros();
std::cout << "Process time = " << (tF - t0) * 0.001 << "ms" << std::endl << std::flush;
vpImage<vpRGBa> I_disp;
vpImageConvert::convert(I_src, I_disp);

unsigned int id = 0;
Expand Down Expand Up @@ -115,7 +115,7 @@ bool run_detection(const vpImage<unsigned char> &I_src, vpCircleHoughTransform &

if (displayCanny) {
vpImage<unsigned char> 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);
}
Expand Down Expand Up @@ -511,7 +511,39 @@ int main(int argc, char **argv)
//! [Algo init]
std::cout << detector;

//! [Display init]
vpImage<unsigned char> I_src;
vpImage<vpRGBa> I_disp;
vpImage<vpRGBa> 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<vpDisplay> dColor = vpDisplayFactory::createDisplay(I_disp, -1, -1, "Input image");;
std::shared_ptr<vpDisplay> 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) {
Expand All @@ -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);
}
}
Expand All @@ -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;
}
Loading