31#include <visp3/core/vpImageConvert.h>
32#include <visp3/core/vpImageMorphology.h>
34#include <visp3/imgproc/vpCircleHoughTransform.h>
38#if (VISP_CXX_STANDARD == VISP_CXX_STANDARD_98)
43bool hasBetterProba(std::pair<size_t, float> a, std::pair<size_t, float> b)
45 return (a.second > b.second);
52 unsigned int nbRows = filter.
getRows();
53 unsigned int nbCols = filter.
getCols();
54 for (
unsigned int r = 0;
r < nbRows; ++
r) {
55 for (
unsigned int c = 0; c < nbCols; ++c) {
56 filter[
r][c] = filter[
r][c] * scale;
90#ifdef VISP_HAVE_NLOHMANN_JSON
91using json = nlohmann::json;
102 std::ifstream file(jsonPath);
104 std::stringstream ss;
105 ss <<
"Problem opening file " << jsonPath <<
". Make sure it exists and is readable" << std::endl;
110 j = json::parse(file);
112 catch (json::parse_error &e) {
113 std::stringstream msg;
114 msg <<
"Could not parse JSON file : \n";
116 msg << e.what() << std::endl;
117 msg <<
"Byte position of error: " << e.byte;
136 const int filterHalfSize = (
m_algoParams.m_gaussianKernelSize + 1) / 2;
137 m_fg.resize(1, filterHalfSize);
145#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
148 const unsigned int nbRows = filter.
getRows();
149 const unsigned int nbCols = filter.
getCols();
150 for (
unsigned int r = 0; r < nbRows; ++r) {
151 for (
unsigned int c = 0; c < nbCols; ++c) {
152 filter[r][c] = filter[r][c] * scale;
158 const int moduloCheckForOddity = 2;
159 if ((
m_algoParams.m_gradientFilterKernelSize % moduloCheckForOddity) != 1) {
168 unsigned int filterHalfSize = (
m_algoParams.m_gradientFilterKernelSize - 1) / 2;
181 std::string errMsg =
"[vpCircleHoughTransform::initGradientFilters] Error: gradient filtering method \"";
183 errMsg +=
"\" has not been implemented yet\n";
190std::vector<vpImageCircle>
198#ifdef HAVE_OPENCV_CORE
199std::vector<vpImageCircle>
208std::vector<vpImageCircle>
211 std::vector<vpImageCircle> detections =
detect(I);
212 size_t nbDetections = detections.size();
215 std::vector<std::pair<size_t, float> > v_id_proba;
216 for (
size_t i = 0; i < nbDetections; ++i) {
218 v_id_proba.push_back(id_proba);
221#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
224 = [](std::pair<size_t, float> a, std::pair<size_t, float> b) {
225 return (a.second > b.second);
228 std::sort(v_id_proba.begin(), v_id_proba.end(), hasBetterProba);
234 limitMin = nbDetections;
237 limitMin = std::min(nbDetections,
static_cast<size_t>(nbCircles));
240 std::vector<vpImageCircle> bestCircles;
245 for (
size_t i = 0; i < nbDetections; ++i) {
246 size_t id = v_id_proba[i].first;
261std::vector<vpImageCircle>
279 const float minRadiusDiff = 3.f;
293 const float minCenterPositionDiff = 3.f;
295 m_algoParams.m_centerXlimits.second +=
static_cast<int>(minCenterPositionDiff / 2.f);
296 m_algoParams.m_centerXlimits.first -=
static_cast<int>(minCenterPositionDiff / 2.f);
299 m_algoParams.m_centerYlimits.second +=
static_cast<int>(minCenterPositionDiff / 2.f);
300 m_algoParams.m_centerYlimits.first -=
static_cast<int>(minCenterPositionDiff / 2.f);
334 bool haveSameCenter = (std::abs(aCenter.
get_u() - bCenter.
get_u())
335 + std::abs(aCenter.
get_v() - bCenter.
get_v())) <= (2. * std::numeric_limits<double>::epsilon());
336 bool haveSameRadius = std::abs(a.
getRadius() - b.
getRadius()) <= (2.f * std::numeric_limits<float>::epsilon());
337 return (haveSameCenter && haveSameRadius);
350 std::cout <<
"\tUse mask: " << (detector.
mp_mask ==
nullptr ?
"false" :
"true") << std::endl;
Implementation of a generic 2D array used as base class for matrices and vectors.
unsigned int getCols() const
unsigned int getRows() const
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
@ notImplementedError
Not implemented.
Class that defines a 2D circle in an image.
vpImagePoint getCenter() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static FilterType getSobelKernelX(FilterType *filter, unsigned int size)
static std::string vpCannyFiltAndGradTypeToStr(const vpCannyFilteringAndGradientType &type)
Cast a vpImageFilter::vpCannyFilteringAndGradientType into a string, to know its name.
@ CANNY_GBLUR_SOBEL_FILTERING
Apply Gaussian blur + Sobel operator on the input image.
@ CANNY_GBLUR_SCHARR_FILTERING
Apply Gaussian blur + Scharr operator on the input image.
static void getGaussianKernel(FilterType *filter, unsigned int size, FilterType sigma=0., bool normalize=true)
static FilterType getScharrKernelY(FilterType *filter, unsigned int size)
static FilterType getSobelKernelY(FilterType *filter, unsigned int size)
static FilterType getScharrKernelX(FilterType *filter, unsigned int size)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.