diff --git a/modules/core/include/visp3/core/vpImageFilter.h b/modules/core/include/visp3/core/vpImageFilter.h index ffc0b3c18f..f1f4aff6bf 100644 --- a/modules/core/include/visp3/core/vpImageFilter.h +++ b/modules/core/include/visp3/core/vpImageFilter.h @@ -70,7 +70,7 @@ class VISP_EXPORT vpImageFilter { public: static void canny(const vpImage &I, vpImage &Ic, unsigned int gaussianFilterSize, - double thresholdCanny, unsigned int apertureSobel); + float thresholdCanny, unsigned int apertureSobel); /*! Apply a 1x3 derivative filter to an image pixel. @@ -1222,11 +1222,11 @@ class VISP_EXPORT vpImageFilter } #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) - static double computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p_cv_blur, double &lowerThresh); - static double computeCannyThreshold(const vpImage &I, double &lowerThresh); - static double median(const cv::Mat &cv_I); - static double median(const vpImage &Isrc); - static std::vector median(const vpImage &Isrc); + static float computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p_cv_blur, float &lowerThresh); + static float computeCannyThreshold(const vpImage &I, float &lowerThresh); + static float median(const cv::Mat &cv_I); + static float median(const vpImage &Isrc); + static std::vector median(const vpImage &Isrc); #endif }; diff --git a/modules/core/src/image/vpImageFilter.cpp b/modules/core/src/image/vpImageFilter.cpp index 470cc2da1a..52538ace0e 100644 --- a/modules/core/src/image/vpImageFilter.cpp +++ b/modules/core/src/image/vpImageFilter.cpp @@ -148,11 +148,11 @@ void vpImageFilter::sepFilter(const vpImage &I, vpImage & * The algorithm is based on based on https://github.com/arnaudgelas/OpenCVExamples/blob/master/cvMat/Statistics/Median/Median.cpp * \param[in] channel : Single channel image in OpenCV format. */ -double vpImageFilter::median(const cv::Mat &channel) +float vpImageFilter::median(const cv::Mat &channel) { - double m = (channel.rows * channel.cols) / 2; + float m = (channel.rows * channel.cols) / 2.f; int bin = 0; - double med = -1.0; + float med = -1.0f; int histSize = 256; float range[] = { 0, 256 }; @@ -165,7 +165,7 @@ double vpImageFilter::median(const cv::Mat &channel) for (int i = 0; i < histSize && med < 0.0; ++i) { bin += cvRound(hist.at(i)); if (bin > m && med < 0.0) - med = i; + med = static_cast(i); } return med; @@ -175,9 +175,10 @@ double vpImageFilter::median(const cv::Mat &channel) * \brief Calculates the median value of a single channel. * The algorithm is based on based on https://github.com/arnaudgelas/OpenCVExamples/blob/master/cvMat/Statistics/Median/Median.cpp * \param[in] Isrc : Gray-level image in ViSP format. + * \return Gray level image median value. * \sa \ref vpImageFilter::median() "vpImageFilter::median(const cv::Mat)" */ -double vpImageFilter::median(const vpImage &Isrc) +float vpImageFilter::median(const vpImage &Isrc) { cv::Mat cv_I; vpImageConvert::convert(Isrc, cv_I); @@ -188,17 +189,17 @@ double vpImageFilter::median(const vpImage &Isrc) * \brief Calculates the median value of a vpRGBa image. * The result is ordered in RGB format. * \param[in] Isrc : RGB image in ViSP format. Alpha channel is ignored. - * \return std::vector meds such as meds[0] = red-channel-median meds[1] = green-channel-median + * \return std::vector meds such as meds[0] = red-channel-median, meds[1] = green-channel-median * and meds[2] = blue-channel-median. * \sa \ref vpImageFilter::median() "vpImageFilter::median(const cv::Mat)" */ -std::vector vpImageFilter::median(const vpImage &Isrc) +std::vector vpImageFilter::median(const vpImage &Isrc) { cv::Mat cv_I_bgr; vpImageConvert::convert(Isrc, cv_I_bgr); std::vector channels; cv::split(cv_I_bgr, channels); - std::vector meds(3); + std::vector meds(3); const int orderMeds[] = { 2, 1, 0 }; // To keep the order R, G, B const int orderCvChannels[] = { 0, 1, 2 }; // Because the order of the cv::Mat is B, G, R for (unsigned int i = 0; i < 3; i++) { @@ -213,9 +214,9 @@ std::vector vpImageFilter::median(const vpImage &Isrc) * \param[in] cv_I : The image, in cv format. * \param[in] p_cv_blur : If different from nullptr, must contain a blurred version of cv_I. * \param[out] lowerThresh : The lower threshold for the Canny edge filter. - * \return double The upper Canny edge filter threshold. + * \return The upper Canny edge filter threshold. */ -double vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p_cv_blur, double &lowerThresh) +float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p_cv_blur, float &lowerThresh) { cv::Mat cv_I_blur; if (p_cv_blur != nullptr) { @@ -232,10 +233,10 @@ double vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat * cv::Mat cv_I_scaled_down; resize(cv_I_blur, cv_I_scaled_down, cv::Size(), scale_down, scale_down, cv::INTER_NEAREST); - double median_pix = vpImageFilter::median(cv_I_scaled_down); - double lower = std::max(0., 0.7 * median_pix); - double upper = std::min(255., 1.3 * median_pix); - upper = std::max(1., upper); + float median_pix = vpImageFilter::median(cv_I_scaled_down); + float lower = std::max(0.f, 0.7f * median_pix); + float upper = std::min(255.f, 1.3f * median_pix); + upper = std::max(1.f, upper); lowerThresh = lower; return upper; } @@ -245,9 +246,9 @@ double vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat * * * \param[in] I : The gray-scale image, in ViSP format. * \param[in] lowerThresh : Canny lower threshold. - * \return double The upper Canny edge filter threshold. + * \return The upper Canny edge filter threshold. */ -double vpImageFilter::computeCannyThreshold(const vpImage &I, double &lowerThresh) +float vpImageFilter::computeCannyThreshold(const vpImage &I, float &lowerThresh) { cv::Mat cv_I; vpImageConvert::convert(I, cv_I); @@ -295,14 +296,14 @@ int main() \param apertureSobel : Size of the mask for the Sobel operator (odd number). */ void vpImageFilter::canny(const vpImage &Isrc, vpImage &Ires, - unsigned int gaussianFilterSize, double thresholdCanny, unsigned int apertureSobel) + unsigned int gaussianFilterSize, float thresholdCanny, unsigned int apertureSobel) { #if defined(HAVE_OPENCV_IMGPROC) cv::Mat img_cvmat, cv_I_blur, edges_cvmat; vpImageConvert::convert(Isrc, img_cvmat); cv::GaussianBlur(img_cvmat, cv_I_blur, cv::Size((int)gaussianFilterSize, (int)gaussianFilterSize), 0, 0); - double upperCannyThresh = thresholdCanny; - double lowerCannyThresh = thresholdCanny / 3.; + float upperCannyThresh = thresholdCanny; + float lowerCannyThresh = thresholdCanny / 3.f; if (upperCannyThresh < 0) { upperCannyThresh = computeCannyThreshold(img_cvmat, &cv_I_blur, lowerCannyThresh); } diff --git a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h index f549759318..b81a7a20db 100644 --- a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h +++ b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h @@ -105,20 +105,20 @@ class VISP_EXPORT vpCircleHoughTransform public: vpCircleHoughTransformParameters() : m_gaussianKernelSize(5) - , m_gaussianStdev(1.) + , m_gaussianStdev(1.f) , m_sobelKernelSize(3) - , m_cannyThresh(-1) + , m_cannyThresh(-1.f) , m_edgeMapFilteringNbIter(1) , m_centerXlimits(std::pair(std::numeric_limits::min(), std::numeric_limits::max())) , m_centerYlimits(std::pair(std::numeric_limits::min(), std::numeric_limits::max())) , m_minRadius(0) , m_maxRadius(1000) , m_dilatationNbIter(1) - , m_centerThresh(50.) - , m_radiusRatioThresh(2.) - , m_circlePerfectness(0.9) - , m_centerMinDist(15.) - , m_mergingRadiusDiffThresh(1.5 * (float)m_centerMinDist) + , m_centerThresh(50.f) + , m_radiusRatioThresh(2.f) + , m_circlePerfectness(0.9f) + , m_centerMinDist(15.f) + , m_mergingRadiusDiffThresh(1.5f * m_centerMinDist) { } @@ -532,7 +532,7 @@ class VISP_EXPORT vpCircleHoughTransform */ inline void setCircleMinRadius(const float &circle_min_radius) { - m_algoParams.m_minRadius = circle_min_radius; + m_algoParams.m_minRadius = static_cast(circle_min_radius); } /*! @@ -541,7 +541,7 @@ class VISP_EXPORT vpCircleHoughTransform */ inline void setCircleMaxRadius(const float &circle_max_radius) { - m_algoParams.m_maxRadius = circle_max_radius; + m_algoParams.m_maxRadius = static_cast(circle_max_radius); } /*! @@ -694,7 +694,7 @@ class VISP_EXPORT vpCircleHoughTransform /*! * Get circles min radius in pixels. */ - inline float getCircleMinRadius() const + inline unsigned int getCircleMinRadius() const { return m_algoParams.m_minRadius; } @@ -702,7 +702,7 @@ class VISP_EXPORT vpCircleHoughTransform /*! * Get circles max radius in pixels. */ - inline float getCircleMaxRadius() const + inline unsigned int getCircleMaxRadius() const { return m_algoParams.m_maxRadius; } diff --git a/modules/imgproc/src/vpCircleHoughTransform.cpp b/modules/imgproc/src/vpCircleHoughTransform.cpp index adeda3a39b..c7291ca8d7 100644 --- a/modules/imgproc/src/vpCircleHoughTransform.cpp +++ b/modules/imgproc/src/vpCircleHoughTransform.cpp @@ -221,7 +221,7 @@ vpCircleHoughTransform::edgeDetection(const vpImage &I) { #if defined(HAVE_OPENCV_IMGPROC) float cannyThresh = m_algoParams.m_cannyThresh; - double lowerThresh; + float lowerThresh; // Apply the Canny edge operator to compute the edge map // The canny method performs Gaussian blur and gradient computation if (m_algoParams.m_cannyThresh < 0.) { @@ -293,7 +293,7 @@ vpCircleHoughTransform::computeCenterCandidates() int minimumXposition = std::max(m_algoParams.m_centerXlimits.first, -1 * (int)m_algoParams.m_maxRadius); int maximumXposition = std::min(m_algoParams.m_centerXlimits.second, (int)(m_algoParams.m_maxRadius + nbCols)); minimumXposition = std::min(minimumXposition, maximumXposition - 1); - float minimumXpositionDouble = minimumXposition; + float minimumXpositionFloat = static_cast(minimumXposition); int offsetX = minimumXposition; int accumulatorWidth = maximumXposition - minimumXposition + 1; if (accumulatorWidth <= 0) { @@ -307,7 +307,7 @@ vpCircleHoughTransform::computeCenterCandidates() int minimumYposition = std::max(m_algoParams.m_centerYlimits.first, -1 * (int)m_algoParams.m_maxRadius); int maximumYposition = std::min(m_algoParams.m_centerYlimits.second, (int)(m_algoParams.m_maxRadius + nbRows)); minimumYposition = std::min(minimumYposition, maximumYposition - 1); - float minimumYpositionDouble = minimumYposition; + float minimumYpositionFloat = static_cast(minimumYposition); int offsetY = minimumYposition; int accumulatorHeight = maximumYposition - minimumYposition + 1; if (accumulatorHeight <= 0) { @@ -338,7 +338,7 @@ vpCircleHoughTransform::computeCenterCandidates() float x1 = (float)c + (float)rad * sx; float y1 = (float)r + (float)rad * sy; - if (x1 < minimumXpositionDouble || y1 < minimumYpositionDouble) { + if (x1 < minimumXpositionFloat || y1 < minimumYpositionFloat) { continue; // If either value is lower than maxRadius, it means that the center is outside the search region. } @@ -346,21 +346,21 @@ vpCircleHoughTransform::computeCenterCandidates() int y_low, y_high; if (x1 > 0.) { - x_low = std::floor(x1); - x_high = std::ceil(x1); + x_low = static_cast(std::floor(x1)); + x_high = static_cast(std::ceil(x1)); } else { - x_low = -1 * std::ceil(-1. * x1); - x_high = -1 * std::floor(-1. * x1); + x_low = -(static_cast(std::ceil(-x1))); + x_high = -(static_cast(std::floor(-x1))); } if (y1 > 0.) { - y_low = std::floor(y1); - y_high = std::ceil(y1); + y_low = static_cast(std::floor(y1)); + y_high = static_cast(std::ceil(y1)); } else { - y_low = -1 * std::ceil(-1. * y1); - y_high = -1 * std::floor(-1. * y1); + y_low = -(static_cast(std::ceil(-1. * y1))); + y_high = -(static_cast(std::floor(-1. * y1))); } auto updateAccumulator = @@ -441,14 +441,14 @@ void vpCircleHoughTransform::computeCircleCandidates() { size_t nbCenterCandidates = m_centerCandidatesList.size(); - unsigned int nbBins = (m_algoParams.m_maxRadius - m_algoParams.m_minRadius + 1)/ m_algoParams.m_centerMinDist; + unsigned int nbBins = static_cast((m_algoParams.m_maxRadius - m_algoParams.m_minRadius + 1)/ m_algoParams.m_centerMinDist); nbBins = std::max((unsigned int)1, nbBins); // Avoid having 0 bins, which causes segfault std::vector radiusAccumList; /*!< Radius accumulator for each center candidates.*/ std::vector radiusActualValueList; /*!< Vector that contains the actual distance between the edge points and the center candidates.*/ unsigned int rmin2 = m_algoParams.m_minRadius * m_algoParams.m_minRadius; - unsigned int rmax2 = m_algoParams.m_maxRadius * m_algoParams.m_maxRadius; - int circlePerfectness2 = m_algoParams.m_circlePerfectness * m_algoParams.m_circlePerfectness; + unsigned int rmax2 = static_cast(m_algoParams.m_maxRadius * m_algoParams.m_maxRadius); + int circlePerfectness2 = static_cast(m_algoParams.m_circlePerfectness * m_algoParams.m_circlePerfectness); for (size_t i = 0; i < nbCenterCandidates; i++) { std::pair centerCandidate = m_centerCandidatesList[i]; @@ -469,12 +469,12 @@ vpCircleHoughTransform::computeCircleCandidates() float gy = m_dIy[edgePoint.first][edgePoint.second]; float grad2 = gx * gx + gy * gy; - int scalProd = rx * gx + ry * gy; - int scalProd2 = scalProd * scalProd; + float scalProd = rx * gx + ry * gy; + float scalProd2 = scalProd * scalProd; if (scalProd2 >= circlePerfectness2 * r2 * grad2) { // Look for the Radius Candidate Bin RCB_k to which d_ij is "the closest" will have an additionnal vote - float r = std::sqrt(r2); - unsigned int r_bin = std::ceil((r - m_algoParams.m_minRadius)/ m_algoParams.m_centerMinDist); + float r = static_cast(std::sqrt(r2)); + unsigned int r_bin = static_cast(std::ceil((r - m_algoParams.m_minRadius)/ m_algoParams.m_centerMinDist)); r_bin = std::min(r_bin, nbBins - 1); radiusAccumList[r_bin]++; radiusActualValueList[r_bin] += r; diff --git a/modules/tracker/me/include/visp3/me/vpMeNurbs.h b/modules/tracker/me/include/visp3/me/vpMeNurbs.h index 3f6a7e5bb2..0ae91e008f 100644 --- a/modules/tracker/me/include/visp3/me/vpMeNurbs.h +++ b/modules/tracker/me/include/visp3/me/vpMeNurbs.h @@ -151,9 +151,9 @@ class VISP_EXPORT vpMeNurbs : public vpMeTracker //! search. bool enableCannyDetection; //! First canny threshold - double cannyTh1; + float cannyTh1; //! Second canny threshold - double cannyTh2; + float cannyTh2; public: vpMeNurbs(); @@ -181,7 +181,7 @@ class VISP_EXPORT vpMeNurbs : public vpMeTracker \param th1 : The first threshold; \param th2 : The second threshold; */ - void setCannyThreshold(double th1, double th2) + void setCannyThreshold(float th1, float th2) { this->cannyTh1 = th1; this->cannyTh2 = th2; diff --git a/modules/tracker/me/src/moving-edges/vpMeNurbs.cpp b/modules/tracker/me/src/moving-edges/vpMeNurbs.cpp index 4bfacc7737..c000eb1587 100644 --- a/modules/tracker/me/src/moving-edges/vpMeNurbs.cpp +++ b/modules/tracker/me/src/moving-edges/vpMeNurbs.cpp @@ -216,7 +216,7 @@ vpMeNurbs::vpMeNurbs() */ vpMeNurbs::vpMeNurbs(const vpMeNurbs &menurbs) : vpMeTracker(menurbs), nurbs(menurbs.nurbs), dist(0.), nbControlPoints(20), beginPtFound(0), endPtFound(0), - enableCannyDetection(false), cannyTh1(100.), cannyTh2(200.) + enableCannyDetection(false), cannyTh1(100.f), cannyTh2(200.f) { dist = menurbs.dist; nbControlPoints = menurbs.nbControlPoints; @@ -547,8 +547,8 @@ void vpMeNurbs::seekExtremitiesCanny(const vpImage &I) std::list ip_edges_list; if (firstBorder != vpImagePoint(-1, -1)) { unsigned int dir; - double fi = firstBorder.get_i(); - double fj = firstBorder.get_j(); + double fi = static_cast(firstBorder.get_i()); + double fj = static_cast(firstBorder.get_j()); double w = Isub.getWidth() - 1; double h = Isub.getHeight() - 1; // if (firstBorder.get_i() == 0) dir = 4;