Skip to content

Commit

Permalink
Merge pull request #1347 from rolalaro/fix_cht_uint_to_float
Browse files Browse the repository at this point in the history
vpCircleHoughTransform typing
  • Loading branch information
fspindle authored Mar 12, 2024
2 parents f04bb21 + 0dc94b4 commit b4efd94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
24 changes: 12 additions & 12 deletions modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class VISP_EXPORT vpCircleHoughTransform
// // Center candidates computation attributes
std::pair<int, int> m_centerXlimits; /*!< Minimum and maximum position on the horizontal axis of the center of the circle we want to detect.*/
std::pair<int, int> m_centerYlimits; /*!< Minimum and maximum position on the vertical axis of the center of the circle we want to detect.*/
unsigned int m_minRadius; /*!< Minimum radius of the circles we want to detect.*/
unsigned int m_maxRadius; /*!< Maximum radius of the circles we want to detect.*/
float m_minRadius; /*!< Minimum radius of the circles we want to detect.*/
float m_maxRadius; /*!< Maximum radius of the circles we want to detect.*/
int m_dilatationKernelSize; /*!< Kernel size of the dilatation that is performed to detect the maximum number of votes for the center candidates.*/
int m_averagingWindowSize; /*!< Size of the averaging window around the maximum number of votes to compute the
center candidate such as it is the barycenter of the window. Must be odd.*/
Expand Down Expand Up @@ -135,8 +135,8 @@ class VISP_EXPORT vpCircleHoughTransform
, m_upperCannyThreshRatio(0.8f)
, m_centerXlimits(std::pair<int, int>(std::numeric_limits<int>::min(), std::numeric_limits<int>::max()))
, m_centerYlimits(std::pair<int, int>(std::numeric_limits<int>::min(), std::numeric_limits<int>::max()))
, m_minRadius(0)
, m_maxRadius(1000)
, m_minRadius(0.f)
, m_maxRadius(1000.f)
, m_dilatationKernelSize(3)
, m_averagingWindowSize(5)
, m_centerMinThresh(50.f)
Expand Down Expand Up @@ -198,8 +198,8 @@ class VISP_EXPORT vpCircleHoughTransform
, const int &edgeMapFilterNbIter
, const std::pair<int, int> &centerXlimits
, const std::pair<int, int> &centerYlimits
, const unsigned int &minRadius
, const unsigned int &maxRadius
, const float &minRadius
, const float &maxRadius
, const int &dilatationKernelSize
, const int &averagingWindowSize
, const float &centerThresh
Expand Down Expand Up @@ -227,8 +227,8 @@ class VISP_EXPORT vpCircleHoughTransform
, m_upperCannyThreshRatio(upperCannyThreshRatio)
, m_centerXlimits(centerXlimits)
, m_centerYlimits(centerYlimits)
, m_minRadius(std::min<unsigned int>(minRadius, maxRadius))
, m_maxRadius(std::max<unsigned int>(minRadius, maxRadius))
, m_minRadius(std::min<float>(minRadius, maxRadius))
, m_maxRadius(std::max<float>(minRadius, maxRadius))
, m_dilatationKernelSize(dilatationKernelSize)
, m_averagingWindowSize(averagingWindowSize)
, m_centerMinThresh(centerThresh)
Expand Down Expand Up @@ -573,9 +573,9 @@ class VISP_EXPORT vpCircleHoughTransform

params.m_centerXlimits = j.value("centerXlimits", params.m_centerXlimits);
params.m_centerYlimits = j.value("centerYlimits", params.m_centerYlimits);
std::pair<unsigned int, unsigned int> radiusLimits = j.value("radiusLimits", std::pair<unsigned int, unsigned int>(params.m_minRadius, params.m_maxRadius));
params.m_minRadius = std::min<unsigned int>(radiusLimits.first, radiusLimits.second);
params.m_maxRadius = std::max<unsigned int>(radiusLimits.first, radiusLimits.second);
std::pair<float, float> radiusLimits = j.value("radiusLimits", std::pair<float, float>(params.m_minRadius, params.m_maxRadius));
params.m_minRadius = std::min<float>(radiusLimits.first, radiusLimits.second);
params.m_maxRadius = std::max<float>(radiusLimits.first, radiusLimits.second);

params.m_dilatationKernelSize = j.value("dilatationKernelSize", params.m_dilatationKernelSize);
params.m_averagingWindowSize = j.value("averagingWindowSize", params.m_averagingWindowSize);
Expand Down Expand Up @@ -621,7 +621,7 @@ class VISP_EXPORT vpCircleHoughTransform
*/
inline friend void to_json(json &j, const vpCircleHoughTransformParameters &params)
{
std::pair<unsigned int, unsigned int> radiusLimits = { params.m_minRadius, params.m_maxRadius };
std::pair<float, float> radiusLimits = { params.m_minRadius, params.m_maxRadius };

j = json {
{"filteringAndGradientType", vpImageFilter::vpCannyFilteringAndGradientTypeToString(params.m_filteringAndGradientType)},
Expand Down
13 changes: 5 additions & 8 deletions modules/imgproc/src/vpCircleHoughTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,30 +600,27 @@ vpCircleHoughTransform::computeCenterCandidates()
// Saving the edge point for further use
m_edgePointsList.push_back(std::pair<unsigned int, unsigned int>(r, c));

float float_minRad = static_cast<float>(m_algoParams.m_minRadius);
float float_maxRad = static_cast<float>(m_algoParams.m_maxRadius);

for (int k1 = 0; k1 < nbDirections; ++k1) {
bool hasToStopLoop = false;
int x_low_prev = std::numeric_limits<int>::max(), y_low_prev, y_high_prev;
int x_high_prev = (y_low_prev = (y_high_prev = x_low_prev));

float rstart = float_minRad, rstop = float_maxRad;
float rstart = m_algoParams.m_minRadius, rstop = m_algoParams.m_maxRadius;
float min_minus_c = minimumXpositionFloat - static_cast<float>(c);
float min_minus_r = minimumYpositionFloat - static_cast<float>(r);
float max_minus_c = maximumXpositionFloat - static_cast<float>(c);
float max_minus_r = maximumYpositionFloat - static_cast<float>(r);
if (sx > 0) {
float rmin = min_minus_c / sx;
rstart = std::max<float>(rmin, float_minRad);
rstart = std::max<float>(rmin, m_algoParams.m_minRadius);
float rmax = max_minus_c / sx;
rstop = std::min<float>(rmax, float_maxRad);
rstop = std::min<float>(rmax, m_algoParams.m_maxRadius);
}
else if (sx < 0) {
float rmin = max_minus_c / sx;
rstart = std::max<float>(rmin, float_minRad);
rstart = std::max<float>(rmin, m_algoParams.m_minRadius);
float rmax = min_minus_c / sx;
rstop = std::min<float>(rmax, float_maxRad);
rstop = std::min<float>(rmax, m_algoParams.m_maxRadius);
}

if (sy > 0) {
Expand Down

0 comments on commit b4efd94

Please sign in to comment.