From 385524749e36115eebc04f61a553399f30c87d57 Mon Sep 17 00:00:00 2001 From: rlagneau Date: Wed, 6 Dec 2023 10:38:05 +0100 Subject: [PATCH] [CLEAN] Clean some warnings arisen by SonarQube + some compilation warnings on Windows --- .../core/include/visp3/core/vpImageFilter.h | 444 ++++++++++-------- modules/core/src/image/vpImageFilter.cpp | 132 +++--- 2 files changed, 314 insertions(+), 262 deletions(-) diff --git a/modules/core/include/visp3/core/vpImageFilter.h b/modules/core/include/visp3/core/vpImageFilter.h index a0087974d4..307adac515 100644 --- a/modules/core/include/visp3/core/vpImageFilter.h +++ b/modules/core/include/visp3/core/vpImageFilter.h @@ -171,7 +171,7 @@ class VISP_EXPORT vpImageFilter #endif } else { - if (filteringType == CANNY_GBLUR_SCHARR_FILTERING || filteringType == CANNY_GBLUR_SOBEL_FILTERING) { + if ((filteringType == CANNY_GBLUR_SCHARR_FILTERING) || (filteringType == CANNY_GBLUR_SOBEL_FILTERING)) { dIx.resize(I.getHeight(), I.getWidth()); dIy.resize(I.getHeight(), I.getWidth()); @@ -311,10 +311,10 @@ class VISP_EXPORT vpImageFilter // Computing the absolute gradient of the image G = |dIx| + |dIy| for (unsigned int r = 0; r < h; r++) { for (unsigned int c = 0; c < w; c++) { - float dx = (float)dIx[r][c]; - float dy = (float)dIy[r][c]; + float dx = static_cast(dIx[r][c]); + float dy = static_cast(dIy[r][c]); float gradient = std::abs(dx) + std::abs(dy); - float gradientClamped = std::min(gradient, (float)std::numeric_limits::max()); + float gradientClamped = std::min(gradient, static_cast(std::numeric_limits::max())); dI[r][c] = static_cast(gradientClamped); } } @@ -326,7 +326,7 @@ class VISP_EXPORT vpImageFilter float accu = 0; float t = (float)(upperThresholdRatio * w * h); float bon = 0; - for (unsigned int i = 0; i < nbBins; i++) { + for (unsigned int i = 0; i < nbBins; ++i) { float tf = hist[i]; accu = accu + tf; if (accu > t) { @@ -348,8 +348,8 @@ class VISP_EXPORT vpImageFilter */ template static double derivativeFilterX(const vpImage &I, unsigned int r, unsigned int c) { - return (2047.0 * (I[r][c + 1] - I[r][c - 1]) + 913.0 * (I[r][c + 2] - I[r][c - 2]) + - 112.0 * (I[r][c + 3] - I[r][c - 3])) / 8418.0; + return (2047.0 * static_cast(I[r][c + 1] - I[r][c - 1]) + 913.0 * static_cast(I[r][c + 2] - I[r][c - 2]) + + 112.0 * static_cast(I[r][c + 3] - I[r][c - 3])) / 8418.0; } /*! @@ -361,8 +361,8 @@ class VISP_EXPORT vpImageFilter */ template static double derivativeFilterY(const vpImage &I, unsigned int r, unsigned int c) { - return (2047.0 * (I[r + 1][c] - I[r - 1][c]) + 913.0 * (I[r + 2][c] - I[r - 2][c]) + - 112.0 * (I[r + 3][c] - I[r - 3][c])) / 8418.0; + return (2047.0 * static_cast(I[r + 1][c] - I[r - 1][c]) + 913.0 * static_cast(I[r + 2][c] - I[r - 2][c]) + + 112.0 * static_cast(I[r + 3][c] - I[r - 3][c])) / 8418.0; } /*! @@ -386,8 +386,8 @@ class VISP_EXPORT vpImageFilter result = 0; - for (i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r][c + i] - I[r][c - i]); + for (i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r][c + i] - I[r][c - i]); } return result; } @@ -413,8 +413,8 @@ class VISP_EXPORT vpImageFilter result = 0; - for (i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r + i][c] - I[r - i][c]); + for (i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r + i][c] - I[r - i][c]); } return result; } @@ -456,13 +456,13 @@ class VISP_EXPORT vpImageFilter If.resize(I.getHeight(), I.getWidth(), 0.0); if (convolve) { - for (unsigned int i = half_size_y; i < I.getHeight() - half_size_y; i++) { - for (unsigned int j = half_size_x; j < I.getWidth() - half_size_x; j++) { + for (unsigned int i = half_size_y; i < (I.getHeight() - half_size_y); ++i) { + for (unsigned int j = half_size_x; j < (I.getWidth() - half_size_x); ++j) { FilterType conv = 0; - for (unsigned int a = 0; a < size_y; a++) { - for (unsigned int b = 0; b < size_x; b++) { - FilterType val = I[i + half_size_y - a][j + half_size_x - b]; // Convolution + for (unsigned int a = 0; a < size_y; ++a) { + for (unsigned int b = 0; b < size_x; ++b) { + FilterType val = static_cast(I[i + half_size_y - a][j + half_size_x - b]); // Convolution conv += M[a][b] * val; } } @@ -471,13 +471,13 @@ class VISP_EXPORT vpImageFilter } } else { - for (unsigned int i = half_size_y; i < I.getHeight() - half_size_y; i++) { - for (unsigned int j = half_size_x; j < I.getWidth() - half_size_x; j++) { + for (unsigned int i = half_size_y; i < (I.getHeight() - half_size_y); ++i) { + for (unsigned int j = half_size_x; j < (I.getWidth() - half_size_x); ++j) { FilterType corr = 0; - for (unsigned int a = 0; a < size_y; a++) { - for (unsigned int b = 0; b < size_x; b++) { - FilterType val = I[i - half_size_y + a][j - half_size_x + b]; // Correlation + for (unsigned int a = 0; a < size_y; ++a) { + for (unsigned int b = 0; b < size_x; ++b) { + FilterType val = static_cast(I[i - half_size_y + a][j - half_size_x + b]); // Correlation corr += M[a][b] * val; } } @@ -513,14 +513,14 @@ class VISP_EXPORT vpImageFilter Iv.resize(I.getHeight(), I.getWidth(), 0.0); if (convolve) { - for (unsigned int v = half_size; v < I.getHeight() - half_size; v++) { - for (unsigned int u = half_size; u < I.getWidth() - half_size; u++) { + for (unsigned int v = half_size; v < (I.getHeight() - half_size); v++) { + for (unsigned int u = half_size; u < (I.getWidth() - half_size); u++) { FilterType conv_u = 0; FilterType conv_v = 0; for (unsigned int a = 0; a < size; a++) { for (unsigned int b = 0; b < size; b++) { - FilterType val = I[v + half_size - a][u + half_size - b]; // Convolution + FilterType val = static_cast(I[v + half_size - a][u + half_size - b]); // Convolution conv_u += M[a][b] * val; conv_v += M[b][a] * val; } @@ -531,14 +531,14 @@ class VISP_EXPORT vpImageFilter } } else { - for (unsigned int v = half_size; v < I.getHeight() - half_size; v++) { - for (unsigned int u = half_size; u < I.getWidth() - half_size; u++) { + for (unsigned int v = half_size; v < (I.getHeight() - half_size); v++) { + for (unsigned int u = half_size; u < (I.getWidth() - half_size); u++) { FilterType conv_u = 0; FilterType conv_v = 0; for (unsigned int a = 0; a < size; a++) { for (unsigned int b = 0; b < size; b++) { - FilterType val = I[v - half_size + a][u - half_size + b]; // Correlation + FilterType val = static_cast(I[v - half_size + a][u - half_size + b]); // Correlation conv_u += M[a][b] * val; conv_v += M[b][a] * val; } @@ -577,25 +577,25 @@ class VISP_EXPORT vpImageFilter static inline unsigned char filterGaussXPyramidal(const vpImage &I, unsigned int i, unsigned int j) { - return (unsigned char)((1. * I[i][j - 2] + 4. * I[i][j - 1] + 6. * I[i][j] + 4. * I[i][j + 1] + 1. * I[i][j + 2]) / 16.); + return static_cast((1. * I[i][j - 2] + 4. * I[i][j - 1] + 6. * I[i][j] + 4. * I[i][j + 1] + 1. * I[i][j + 2]) / 16.); } static inline unsigned char filterGaussYPyramidal(const vpImage &I, unsigned int i, unsigned int j) { - return (unsigned char)((1. * I[i - 2][j] + 4. * I[i - 1][j] + 6. * I[i][j] + 4. * I[i + 1][j] + 1. * I[i + 2][j]) / 16.); + return static_cast((1. * I[i - 2][j] + 4. * I[i - 1][j] + 6. * I[i][j] + 4. * I[i + 1][j] + 1. * I[i + 2][j]) / 16.); } template static void filterX(const vpImage &I, vpImage &dIx, const FilterType *filter, unsigned int size) { dIx.resize(I.getHeight(), I.getWidth()); - for (unsigned int i = 0; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < (size - 1) / 2; j++) { + for (unsigned int i = 0; i < I.getHeight(); ++i) { + for (unsigned int j = 0; j < ((size - 1) / 2); ++j) { dIx[i][j] = vpImageFilter::filterXLeftBorder(I, i, j, filter, size); } - for (unsigned int j = (size - 1) / 2; j < I.getWidth() - (size - 1) / 2; j++) { + for (unsigned int j = (size - 1) / 2; j < (I.getWidth() - (size - 1) / 2); ++j) { dIx[i][j] = vpImageFilter::filterX(I, i, j, filter, size); } - for (unsigned int j = I.getWidth() - (size - 1) / 2; j < I.getWidth(); j++) { + for (unsigned int j = I.getWidth() - (size - 1) / 2; j < I.getWidth(); ++j) { dIx[i][j] = vpImageFilter::filterXRightBorder(I, i, j, filter, size); } } @@ -613,10 +613,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r][c + i] + I[r][c - i]); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r][c + i] + I[r][c - i]); } - return result + filter[0] * I[r][c]; + return result + filter[0] * static_cast(I[r][c]); } static inline double filterXR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -625,10 +625,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r][c + i].R + I[r][c - i].R); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); } - return result + filter[0] * I[r][c].R; + return result + filter[0] * static_cast(I[r][c].R); } static inline double filterXG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -637,10 +637,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r][c + i].G + I[r][c - i].G); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); } - return result + filter[0] * I[r][c].G; + return result + filter[0] * static_cast(I[r][c].G); } static inline double filterXB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -649,10 +649,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r][c + i].B + I[r][c - i].B); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); } - return result + filter[0] * I[r][c].B; + return result + filter[0] * static_cast(I[r][c].B); } template @@ -663,11 +663,13 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c > i) + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (c > i) { result += filter[i] * static_cast(I[r][c + i] + I[r][c - i]); - else + } + else { result += filter[i] * static_cast(I[r][c + i] + I[r][i - c]); + } } return result + filter[0] * static_cast(I[r][c]); } @@ -679,13 +681,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c > i) - result += filter[i] * (I[r][c + i].R + I[r][c - i].R); - else - result += filter[i] * (I[r][c + i].R + I[r][i - c].R); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (c > i) { + result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); + } + else { + result += filter[i] * static_cast(I[r][c + i].R + I[r][i - c].R); + } } - return result + filter[0] * I[r][c].R; + return result + filter[0] * static_cast(I[r][c].R); } static inline double filterXLeftBorderG(const vpImage &I, unsigned int r, unsigned int c, @@ -695,13 +699,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c > i) - result += filter[i] * (I[r][c + i].G + I[r][c - i].G); - else - result += filter[i] * (I[r][c + i].G + I[r][i - c].G); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (c > i) { + result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); + } + else { + result += filter[i] * static_cast(I[r][c + i].G + I[r][i - c].G); + } } - return result + filter[0] * I[r][c].G; + return result + filter[0] * static_cast(I[r][c].G); } static inline double filterXLeftBorderB(const vpImage &I, unsigned int r, unsigned int c, @@ -711,13 +717,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c > i) - result += filter[i] * (I[r][c + i].B + I[r][c - i].B); - else - result += filter[i] * (I[r][c + i].B + I[r][i - c].B); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (c > i) { + result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); + } + else { + result += filter[i] * static_cast(I[r][c + i].B + I[r][i - c].B); + } } - return result + filter[0] * I[r][c].B; + return result + filter[0] * static_cast(I[r][c].B); } template @@ -728,11 +736,13 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c + i < I.getWidth()) + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((c + i) < I.getWidth()) { result += filter[i] * static_cast(I[r][c + i] + I[r][c - i]); - else + } + else { result += filter[i] * static_cast(I[r][2 * I.getWidth() - c - i - 1] + I[r][c - i]); + } } return result + filter[0] * static_cast(I[r][c]); } @@ -744,13 +754,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c + i < I.getWidth()) - result += filter[i] * (I[r][c + i].R + I[r][c - i].R); - else - result += filter[i] * (I[r][2 * I.getWidth() - c - i - 1].R + I[r][c - i].R); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((c + i) < I.getWidth()) { + result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); + } + else { + result += filter[i] * static_cast(I[r][2 * I.getWidth() - c - i - 1].R + I[r][c - i].R); + } } - return result + filter[0] * I[r][c].R; + return result + filter[0] * static_cast(I[r][c].R); } static inline double filterXRightBorderG(const vpImage &I, unsigned int r, unsigned int c, @@ -760,13 +772,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c + i < I.getWidth()) - result += filter[i] * (I[r][c + i].G + I[r][c - i].G); - else - result += filter[i] * (I[r][2 * I.getWidth() - c - i - 1].G + I[r][c - i].G); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((c + i) < I.getWidth()) { + result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); + } + else { + result += filter[i] * static_cast(I[r][2 * I.getWidth() - c - i - 1].G + I[r][c - i].G); + } } - return result + filter[0] * I[r][c].G; + return result + filter[0] * static_cast(I[r][c].G); } static inline double filterXRightBorderB(const vpImage &I, unsigned int r, unsigned int c, @@ -776,13 +790,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (c + i < I.getWidth()) - result += filter[i] * (I[r][c + i].B + I[r][c - i].B); - else - result += filter[i] * (I[r][2 * I.getWidth() - c - i - 1].B + I[r][c - i].B); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((c + i) < I.getWidth()) { + result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); + } + else { + result += filter[i] * static_cast(I[r][2 * I.getWidth() - c - i - 1].B + I[r][c - i].B); + } } - return result + filter[0] * I[r][c].B; + return result + filter[0] * static_cast(I[r][c].B); } static void filterY(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); @@ -794,18 +810,18 @@ class VISP_EXPORT vpImageFilter static void filterY(const vpImage &I, vpImage &dIy, const FilterType *filter, unsigned int size) { dIy.resize(I.getHeight(), I.getWidth()); - for (unsigned int i = 0; i < (size - 1) / 2; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + for (unsigned int i = 0; i < ((size - 1) / 2); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { dIy[i][j] = vpImageFilter::filterYTopBorder(I, i, j, filter, size); } } - for (unsigned int i = (size - 1) / 2; i < I.getHeight() - (size - 1) / 2; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + for (unsigned int i = (size - 1) / 2; i < (I.getHeight() - (size - 1) / 2); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { dIy[i][j] = vpImageFilter::filterY(I, i, j, filter, size); } } - for (unsigned int i = I.getHeight() - (size - 1) / 2; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + for (unsigned int i = I.getHeight() - (size - 1) / 2; i < I.getHeight(); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { dIy[i][j] = vpImageFilter::filterYBottomBorder(I, i, j, filter, size); } } @@ -818,10 +834,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r + i][c] + I[r - i][c]); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r + i][c] + I[r - i][c]); } - return result + filter[0] * I[r][c]; + return result + filter[0] * static_cast(I[r][c]); } static inline double filterYR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -830,10 +846,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r + i][c].R + I[r - i][c].R); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); } - return result + filter[0] * I[r][c].R; + return result + filter[0] * static_cast(I[r][c].R); } static inline double filterYG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { @@ -841,10 +857,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r + i][c].G + I[r - i][c].G); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); } - return result + filter[0] * I[r][c].G; + return result + filter[0] * static_cast(I[r][c].G); } static inline double filterYB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -853,10 +869,10 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - result += filter[i] * (I[r + i][c].B + I[r - i][c].B); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); } - return result + filter[0] * I[r][c].B; + return result + filter[0] * static_cast(I[r][c].B); } template @@ -867,11 +883,13 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r > i) + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (r > i) { result += filter[i] * static_cast(I[r + i][c] + I[r - i][c]); - else + } + else { result += filter[i] * static_cast(I[r + i][c] + I[i - r][c]); + } } return result + filter[0] * static_cast(I[r][c]); } @@ -882,13 +900,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r > i) - result += filter[i] * (I[r + i][c].R + I[r - i][c].R); - else - result += filter[i] * (I[r + i][c].R + I[i - r][c].R); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (r > i) { + result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); + } + else { + result += filter[i] * static_cast(I[r + i][c].R + I[i - r][c].R); + } } - return result + filter[0] * I[r][c].R; + return result + filter[0] * static_cast(I[r][c].R); } double static inline filterYTopBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -897,13 +917,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r > i) - result += filter[i] * (I[r + i][c].G + I[r - i][c].G); - else - result += filter[i] * (I[r + i][c].G + I[i - r][c].G); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (r > i) { + result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); + } + else { + result += filter[i] * static_cast(I[r + i][c].G + I[i - r][c].G); + } } - return result + filter[0] * I[r][c].G; + return result + filter[0] * static_cast(I[r][c].G); } double static inline filterYTopBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -912,13 +934,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r > i) - result += filter[i] * (I[r + i][c].B + I[r - i][c].B); - else - result += filter[i] * (I[r + i][c].B + I[i - r][c].B); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if (r > i) { + result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); + } + else { + result += filter[i] * static_cast(I[r + i][c].B + I[i - r][c].B); + } } - return result + filter[0] * I[r][c].B; + return result + filter[0] * static_cast(I[r][c].B); } template @@ -929,11 +953,13 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r + i < I.getHeight()) + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((r + i) < I.getHeight()) { result += filter[i] * static_cast(I[r + i][c] + I[r - i][c]); - else + } + else { result += filter[i] * static_cast(I[2 * I.getHeight() - r - i - 1][c] + I[r - i][c]); + } } return result + filter[0] * static_cast(I[r][c]); } @@ -945,13 +971,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r + i < I.getHeight()) - result += filter[i] * (I[r + i][c].R + I[r - i][c].R); - else - result += filter[i] * (I[2 * I.getHeight() - r - i - 1][c].R + I[r - i][c].R); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((r + i) < I.getHeight()) { + result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); + } + else { + result += filter[i] * static_cast(I[2 * I.getHeight() - r - i - 1][c].R + I[r - i][c].R); + } } - return result + filter[0] * I[r][c].R; + return result + filter[0] * static_cast(I[r][c].R); } double static inline filterYBottomBorderG(const vpImage &I, unsigned int r, unsigned int c, @@ -961,13 +989,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r + i < I.getHeight()) - result += filter[i] * (I[r + i][c].G + I[r - i][c].G); - else - result += filter[i] * (I[2 * I.getHeight() - r - i - 1][c].G + I[r - i][c].G); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((r + i) < I.getHeight()) { + result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); + } + else { + result += filter[i] * static_cast(I[2 * I.getHeight() - r - i - 1][c].G + I[r - i][c].G); + } } - return result + filter[0] * I[r][c].G; + return result + filter[0] * static_cast(I[r][c].G); } double static inline filterYBottomBorderB(const vpImage &I, unsigned int r, unsigned int c, @@ -977,13 +1007,15 @@ class VISP_EXPORT vpImageFilter result = 0; - for (unsigned int i = 1; i <= (size - 1) / 2; i++) { - if (r + i < I.getHeight()) - result += filter[i] * (I[r + i][c].B + I[r - i][c].B); - else - result += filter[i] * (I[2 * I.getHeight() - r - i - 1][c].B + I[r - i][c].B); + for (unsigned int i = 1; i <= ((size - 1) / 2); ++i) { + if ((r + i) < I.getHeight()) { + result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); + } + else { + result += filter[i] * static_cast(I[2 * I.getHeight() - r - i - 1][c].B + I[r - i][c].B); + } } - return result + filter[0] * I[r][c].B; + return result + filter[0] * static_cast(I[r][c].B); } /*! @@ -1052,28 +1084,30 @@ class VISP_EXPORT vpImageFilter template static void getGaussianKernel(FilterType *filter, unsigned int size, FilterType sigma = 0., bool normalize = true) { - if (size % 2 != 1) + if ((size % 2) != 1) { throw(vpImageException(vpImageException::incorrectInitializationError, "Bad Gaussian filter size")); + } - if (sigma <= 0) + if (sigma <= 0) { sigma = static_cast((size - 1) / 6.0); + } - int middle = (int)(size - 1) / 2; + int middle = (static_cast(size) - 1) / 2; FilterType sigma2 = static_cast(vpMath::sqr(sigma)); FilterType coef1 = static_cast(1. / (sigma * sqrt(2. * M_PI))); FilterType _2_sigma2 = static_cast(2. * sigma2); - for (int i = 0; i <= middle; i++) { - filter[i] = coef1 * exp(-(i * i) / _2_sigma2); + for (int i = 0; i <= middle; ++i) { + filter[i] = coef1 * static_cast(exp(-(i * i) / _2_sigma2)); } if (normalize) { // renormalization FilterType sum = 0; - for (int i = 1; i <= middle; i++) { + for (int i = 1; i <= middle; ++i) { sum += 2 * filter[i]; } sum += filter[0]; - for (int i = 0; i <= middle; i++) { + for (int i = 0; i <= middle; ++i) { filter[i] = filter[i] / sum; } } @@ -1096,31 +1130,33 @@ class VISP_EXPORT vpImageFilter template static void getGaussianDerivativeKernel(FilterType *filter, unsigned int size, FilterType sigma = 0., bool normalize = true) { - if (size % 2 != 1) + if ((size % 2) != 1) { throw(vpImageException(vpImageException::incorrectInitializationError, "Bad Gaussian filter size")); + } - if (sigma <= 0) + if (sigma <= 0) { sigma = static_cast((size - 1) / 6.0); + } - int middle = (int)(size - 1) / 2; + int middle = (static_cast(size) - 1) / 2; FilterType sigma2 = static_cast(vpMath::sqr(sigma)); FilterType coef_1 = static_cast(1. / (sigma * sqrt(2. * M_PI))); FilterType coef_1_over_2 = coef_1 / static_cast(2.); FilterType _2_coef_1 = static_cast(2.) * coef_1; FilterType _2_sigma2 = static_cast(2. * sigma2); filter[0] = 0.; - for (int i = 1; i <= middle; i++) { + for (int i = 1; i <= middle; ++i) { filter[i] = -coef_1_over_2 * (static_cast(exp(-((i + 1) * (i + 1)) / _2_sigma2)) - static_cast(exp(-((i - 1) * (i - 1)) / _2_sigma2))); } if (normalize) { FilterType sum = 0; - for (int i = 1; i <= middle; i++) { + for (int i = 1; i <= middle; ++i) { sum += _2_coef_1 * static_cast(exp(-(i * i) / _2_sigma2)); } sum += coef_1; - for (int i = 1; i <= middle; i++) { + for (int i = 1; i <= middle; ++i) { filter[i] = filter[i] / sum; } } @@ -1132,15 +1168,15 @@ class VISP_EXPORT vpImageFilter { dIx.resize(I.getHeight(), I.getWidth()); // dIx=0; - for (unsigned int i = 0; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < 3; j++) { - dIx[i][j] = 0; + for (unsigned int i = 0; i < I.getHeight(); ++i) { + for (unsigned int j = 0; j < 3; ++j) { + dIx[i][j] = static_cast(0); } - for (unsigned int j = 3; j < I.getWidth() - 3; j++) { - dIx[i][j] = vpImageFilter::derivativeFilterX(I, i, j); + for (unsigned int j = 3; j < (I.getWidth() - 3); ++j) { + dIx[i][j] = static_cast(vpImageFilter::derivativeFilterX(I, i, j)); } - for (unsigned int j = I.getWidth() - 3; j < I.getWidth(); j++) { - dIx[i][j] = 0; + for (unsigned int j = I.getWidth() - 3; j < I.getWidth(); ++j) { + dIx[i][j] = static_cast(0); } } } @@ -1149,15 +1185,15 @@ class VISP_EXPORT vpImageFilter static void getGradX(const vpImage &I, vpImage &dIx, const FilterType *filter, unsigned int size) { dIx.resize(I.getHeight(), I.getWidth()); - for (unsigned int i = 0; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < (size - 1) / 2; j++) { - dIx[i][j] = 0; + for (unsigned int i = 0; i < I.getHeight(); ++i) { + for (unsigned int j = 0; j < ((size - 1) / 2); ++j) { + dIx[i][j] = static_cast(0); } - for (unsigned int j = (size - 1) / 2; j < I.getWidth() - (size - 1) / 2; j++) { + for (unsigned int j = (size - 1) / 2; j < (I.getWidth() - (size - 1) / 2); ++j) { dIx[i][j] = vpImageFilter::derivativeFilterX(I, i, j, filter, size); } - for (unsigned int j = I.getWidth() - (size - 1) / 2; j < I.getWidth(); j++) { - dIx[i][j] = 0; + for (unsigned int j = I.getWidth() - (size - 1) / 2; j < I.getWidth(); ++j) { + dIx[i][j] = static_cast(0); } } } @@ -1186,19 +1222,19 @@ class VISP_EXPORT vpImageFilter static void getGradY(const vpImage &I, vpImage &dIy) { dIy.resize(I.getHeight(), I.getWidth()); - for (unsigned int i = 0; i < 3; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { - dIy[i][j] = 0; + for (unsigned int i = 0; i < 3; ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { + dIy[i][j] = static_cast(0); } } - for (unsigned int i = 3; i < I.getHeight() - 3; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { - dIy[i][j] = vpImageFilter::derivativeFilterY(I, i, j); + for (unsigned int i = 3; i < (I.getHeight() - 3); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { + dIy[i][j] = static_cast(vpImageFilter::derivativeFilterY(I, i, j)); } } - for (unsigned int i = I.getHeight() - 3; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { - dIy[i][j] = 0; + for (unsigned int i = I.getHeight() - 3; i < I.getHeight(); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { + dIy[i][j] = static_cast(0); } } } @@ -1207,19 +1243,19 @@ class VISP_EXPORT vpImageFilter static void getGradY(const vpImage &I, vpImage &dIy, const FilterType *filter, unsigned int size) { dIy.resize(I.getHeight(), I.getWidth()); - for (unsigned int i = 0; i < (size - 1) / 2; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { - dIy[i][j] = 0; + for (unsigned int i = 0; i < ((size - 1) / 2); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { + dIy[i][j] = static_cast(0); } } - for (unsigned int i = (size - 1) / 2; i < I.getHeight() - (size - 1) / 2; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + for (unsigned int i = (size - 1) / 2; i < (I.getHeight() - (size - 1) / 2); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { dIy[i][j] = vpImageFilter::derivativeFilterY(I, i, j, filter, size); } } - for (unsigned int i = I.getHeight() - (size - 1) / 2; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { - dIy[i][j] = 0; + for (unsigned int i = I.getHeight() - (size - 1) / 2; i < I.getHeight(); ++i) { + for (unsigned int j = 0; j < I.getWidth(); ++j) { + dIy[i][j] = static_cast(0); } } } @@ -1287,10 +1323,10 @@ class VISP_EXPORT vpImageFilter const unsigned int kernel_size = size * 2 + 1; if (kernel_size == 3) { memcpy(filter, ScharrY3x3, kernel_size * kernel_size * sizeof(FilterType)); - return 1 / 32.0; + return static_cast(1.0 / 32.0); } - return 0.; + return static_cast(0.); } /*! @@ -1303,10 +1339,12 @@ class VISP_EXPORT vpImageFilter template inline static FilterType getSobelKernelX(FilterType *filter, unsigned int size) { - if (size == 0) + if (size == 0) { throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size 0!"); - if (size > 20) + } + if (size > 20) { throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size > 20!"); + } vpArray2D SobelY(size * 2 + 1, size * 2 + 1); FilterType norm = getSobelKernelY(SobelY.data, size); @@ -1342,10 +1380,12 @@ class VISP_EXPORT vpImageFilter smoothingKernel[2][1] = 2.0; smoothingKernel[2][2] = 1.0; - if (size == 0) + if (size == 0) { throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size 0!"); - if (size > 20) + } + if (size > 20) { throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size > 20!"); + } const unsigned int kernel_size = size * 2 + 1; FilterType scale = static_cast(1. / 8.); // Scale to normalize Sobel3x3 @@ -1353,12 +1393,12 @@ class VISP_EXPORT vpImageFilter memcpy(filter, SobelY3x3, kernel_size * kernel_size * sizeof(FilterType)); return scale; } - scale *= 1./ 16.; // Sobel5x5 is the convolution of smoothingKernel, which needs 1/16 scale factor, with Sobel3x3 + scale *= static_cast(1./ 16.); // Sobel5x5 is the convolution of smoothingKernel, which needs 1/16 scale factor, with Sobel3x3 if (kernel_size == 5) { memcpy(filter, SobelY5x5, kernel_size * kernel_size * sizeof(FilterType)); return scale; } - scale *= 1./ 16.; // Sobel7x7 is the convolution of smoothingKernel, which needs 1/16 scale factor, with Sobel5x5 + scale *= static_cast(1./ 16.); // Sobel7x7 is the convolution of smoothingKernel, which needs 1/16 scale factor, with Sobel5x5 if (kernel_size == 7) { memcpy(filter, SobelY7x7, kernel_size * kernel_size * sizeof(FilterType)); return scale; @@ -1366,10 +1406,10 @@ class VISP_EXPORT vpImageFilter vpArray2D sobelY(7, 7); memcpy(sobelY.data, SobelY7x7, sobelY.getRows() * sobelY.getCols() * sizeof(FilterType)); - for (unsigned int i = 4; i <= size; i++) { + for (unsigned int i = 4; i <= size; ++i) { sobelY = vpArray2D::conv2(sobelY, smoothingKernel, "full"); // Sobel(N+1)x(N+1) is the convolution of smoothingKernel, which needs 1/16 scale factor, with SobelNxN - scale *= 1./ 16.; + scale *= static_cast(1./ 16.); } memcpy(filter, sobelY.data, sobelY.getRows() * sobelY.getCols() * sizeof(FilterType)); diff --git a/modules/core/src/image/vpImageFilter.cpp b/modules/core/src/image/vpImageFilter.cpp index 629ee1e063..52ede64e8a 100644 --- a/modules/core/src/image/vpImageFilter.cpp +++ b/modules/core/src/image/vpImageFilter.cpp @@ -48,12 +48,12 @@ std::string vpImageFilter::vpCannyBackendTypeList(const std::string &pref, const const std::string &suf) { std::string list(pref); - for (unsigned int i = 0; i < vpCannyBackendType::CANNY_COUNT_BACKEND - 1; i++) { - vpCannyBackendType type = (vpCannyBackendType)i; + for (unsigned int i = 0; i < (vpCannyBackendType::CANNY_COUNT_BACKEND - 1); ++i) { + vpCannyBackendType type = static_cast(i); list += vpCannyBackendTypeToString(type); list += sep; } - vpCannyBackendType type = (vpCannyBackendType)(vpCannyBackendType::CANNY_COUNT_BACKEND - 1); + vpCannyBackendType type = static_cast(vpCannyBackendType::CANNY_COUNT_BACKEND - 1); list += vpCannyBackendTypeToString(type); list += suf; return list; @@ -92,14 +92,16 @@ vpImageFilter::vpCannyBackendType vpImageFilter::vpCannyBackendTypeFromString(co { vpCannyBackendType type(vpCannyBackendType::CANNY_COUNT_BACKEND); std::string nameLowerCase = vpIoTools::toLowerCase(name); - unsigned int count = (unsigned int)vpCannyBackendType::CANNY_COUNT_BACKEND; - bool found = false; - for (unsigned int i = 0; i < count && !found; i++) { - vpCannyBackendType temp = (vpCannyBackendType)i; + unsigned int count = static_cast(vpCannyBackendType::CANNY_COUNT_BACKEND); + bool notFound = true; + unsigned int i = 0; + while ((i < count) && notFound) { + vpCannyBackendType temp = static_cast(i); if (nameLowerCase == vpCannyBackendTypeToString(temp)) { type = temp; - found = true; + notFound = false; } + ++i; } return type; } @@ -116,12 +118,12 @@ std::string vpImageFilter::vpCannyFilteringAndGradientTypeList(const std::string const std::string &suf) { std::string list(pref); - for (unsigned int i = 0; i < vpCannyFilteringAndGradientType::CANNY_COUNT_FILTERING - 1; i++) { - vpCannyFilteringAndGradientType type = (vpCannyFilteringAndGradientType)i; + for (unsigned int i = 0; i < (vpCannyFilteringAndGradientType::CANNY_COUNT_FILTERING - 1); ++i) { + vpCannyFilteringAndGradientType type = static_cast(i); list += vpCannyFilteringAndGradientTypeToString(type); list += sep; } - vpCannyFilteringAndGradientType type = (vpCannyFilteringAndGradientType)(CANNY_COUNT_FILTERING - 1); + vpCannyFilteringAndGradientType type = static_cast(CANNY_COUNT_FILTERING - 1); list += vpCannyFilteringAndGradientTypeToString(type); list += suf; return list; @@ -160,14 +162,16 @@ vpImageFilter::vpCannyFilteringAndGradientType vpImageFilter::vpCannyFilteringAn { vpCannyFilteringAndGradientType type(vpCannyFilteringAndGradientType::CANNY_COUNT_FILTERING); std::string nameLowerCase = vpIoTools::toLowerCase(name); - unsigned int count = (unsigned int)vpCannyFilteringAndGradientType::CANNY_COUNT_FILTERING; - bool found = false; - for (unsigned int i = 0; i < count && !found; i++) { - vpCannyFilteringAndGradientType temp = (vpCannyFilteringAndGradientType)i; + unsigned int count = static_cast(vpCannyFilteringAndGradientType::CANNY_COUNT_FILTERING); + bool notFound = true; + unsigned int i = 0; + while ((i < count) && notFound) { + vpCannyFilteringAndGradientType temp = static_cast(i); if (nameLowerCase == vpCannyFilteringAndGradientTypeToString(temp)) { type = temp; - found = true; + notFound = false; } + ++i; } return type; } @@ -260,27 +264,28 @@ void vpImageFilter::filter(const vpImage &I, vpImage &I, vpImage &If, const vpColVector &kernelH, const vpColVector &kernelV) { - unsigned int size = kernelH.size(); + unsigned int size = kernelH.size(), sizeV = kernelV.size(); + unsigned int widthI = I.getWidth(), heightI = I.getHeight(); unsigned int half_size = size / 2; - If.resize(I.getHeight(), I.getWidth(), 0.0); - vpImage I_filter(I.getHeight(), I.getWidth(), 0.0); + If.resize(heightI, widthI, 0.0); + vpImage I_filter(heightI, widthI, 0.0); - for (unsigned int i = 0; i < I.getHeight(); i++) { - for (unsigned int j = half_size; j < I.getWidth() - half_size; j++) { + for (unsigned int i = 0; i < heightI; ++i) { + for (unsigned int j = half_size; j < (widthI - half_size); ++j) { double conv = 0.0; - for (unsigned int a = 0; a < kernelH.size(); a++) { - conv += kernelH[a] * I[i][j + half_size - a]; + for (unsigned int a = 0; a < size; ++a) { + conv += kernelH[a] * static_cast(I[i][j + half_size - a]); } I_filter[i][j] = conv; } } - for (unsigned int i = half_size; i < I.getHeight() - half_size; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + for (unsigned int i = half_size; i < (heightI - half_size); ++i) { + for (unsigned int j = 0; j < widthI; ++j) { double conv = 0.0; - for (unsigned int a = 0; a < kernelV.size(); a++) { + for (unsigned int a = 0; a < sizeV; ++a) { conv += kernelV[a] * I_filter[i + half_size - a][j]; } @@ -311,19 +316,20 @@ void vpImageFilter::filterX(const vpImage &I, vpImage &I, vpImage &dIx, const double *filter, unsigned int size) { - dIx.resize(I.getHeight(), I.getWidth()); - for (unsigned int i = 0; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < (size - 1) / 2; j++) { + const unsigned int heightI = I.getHeight(), widthI = I.getWidth(); + dIx.resize(heightI, widthI); + for (unsigned int i = 0; i < heightI; i++) { + for (unsigned int j = 0; j < ((size - 1) / 2); ++j) { dIx[i][j].R = static_cast(vpImageFilter::filterXLeftBorderR(I, i, j, filter, size)); dIx[i][j].G = static_cast(vpImageFilter::filterXLeftBorderG(I, i, j, filter, size)); dIx[i][j].B = static_cast(vpImageFilter::filterXLeftBorderB(I, i, j, filter, size)); } - for (unsigned int j = (size - 1) / 2; j < I.getWidth() - (size - 1) / 2; j++) { + for (unsigned int j = (size - 1) / 2; j < (widthI - (size - 1) / 2); ++j) { dIx[i][j].R = static_cast(vpImageFilter::filterXR(I, i, j, filter, size)); dIx[i][j].G = static_cast(vpImageFilter::filterXG(I, i, j, filter, size)); dIx[i][j].B = static_cast(vpImageFilter::filterXB(I, i, j, filter, size)); } - for (unsigned int j = I.getWidth() - (size - 1) / 2; j < I.getWidth(); j++) { + for (unsigned int j = widthI - (size - 1) / 2; j < widthI; ++j) { dIx[i][j].R = static_cast(vpImageFilter::filterXRightBorderR(I, i, j, filter, size)); dIx[i][j].G = static_cast(vpImageFilter::filterXRightBorderG(I, i, j, filter, size)); dIx[i][j].B = static_cast(vpImageFilter::filterXRightBorderB(I, i, j, filter, size)); @@ -353,23 +359,24 @@ void vpImageFilter::filterY(const vpImage &I, vpImage &I, vpImage &dIy, const double *filter, unsigned int size) { - dIy.resize(I.getHeight(), I.getWidth()); - for (unsigned int i = 0; i < (size - 1) / 2; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + const unsigned int heightI = I.getHeight(), widthI = I.getWidth(); + dIy.resize(heightI, widthI); + for (unsigned int i = 0; i < (size - 1) / 2; ++i) { + for (unsigned int j = 0; j < widthI; ++j) { dIy[i][j].R = static_cast(vpImageFilter::filterYTopBorderR(I, i, j, filter, size)); dIy[i][j].G = static_cast(vpImageFilter::filterYTopBorderG(I, i, j, filter, size)); dIy[i][j].B = static_cast(vpImageFilter::filterYTopBorderB(I, i, j, filter, size)); } } - for (unsigned int i = (size - 1) / 2; i < I.getHeight() - (size - 1) / 2; i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + for (unsigned int i = (size - 1) / 2; i < (heightI - (size - 1) / 2); ++i) { + for (unsigned int j = 0; j < widthI; ++j) { dIy[i][j].R = static_cast(vpImageFilter::filterYR(I, i, j, filter, size)); dIy[i][j].G = static_cast(vpImageFilter::filterYG(I, i, j, filter, size)); dIy[i][j].B = static_cast(vpImageFilter::filterYB(I, i, j, filter, size)); } } - for (unsigned int i = I.getHeight() - (size - 1) / 2; i < I.getHeight(); i++) { - for (unsigned int j = 0; j < I.getWidth(); j++) { + for (unsigned int i = heightI - (size - 1) / 2; i < heightI; ++i) { + for (unsigned int j = 0; j < widthI; ++j) { dIy[i][j].R = static_cast(vpImageFilter::filterYBottomBorderR(I, i, j, filter, size)); dIy[i][j].G = static_cast(vpImageFilter::filterYBottomBorderG(I, i, j, filter, size)); dIy[i][j].B = static_cast(vpImageFilter::filterYBottomBorderB(I, i, j, filter, size)); @@ -524,12 +531,13 @@ void vpImageFilter::getGaussPyramidal(const vpImage &I, vpImage &I, vpImage &GI) { - unsigned int w = I.getWidth() / 2; + const unsigned int w = I.getWidth() / 2; + const unsigned int height = I.getHeight(); - GI.resize(I.getHeight(), w); - for (unsigned int i = 0; i < I.getHeight(); i++) { + GI.resize(height, w); + for (unsigned int i = 0; i < height; ++i) { GI[i][0] = I[i][0]; - for (unsigned int j = 1; j < w - 1; j++) { + for (unsigned int j = 1; j < (w - 1); ++j) { GI[i][j] = vpImageFilter::filterGaussXPyramidal(I, i, 2 * j); } GI[i][w - 1] = I[i][2 * w - 1]; @@ -538,12 +546,13 @@ void vpImageFilter::getGaussXPyramidal(const vpImage &I, vpImage< void vpImageFilter::getGaussYPyramidal(const vpImage &I, vpImage &GI) { - unsigned int h = I.getHeight() / 2; + const unsigned int h = I.getHeight() / 2; + const unsigned int width = I.getWidth(); - GI.resize(h, I.getWidth()); - for (unsigned int j = 0; j < I.getWidth(); j++) { + GI.resize(h, width); + for (unsigned int j = 0; j < width; ++j) { GI[0][j] = I[0][j]; - for (unsigned int i = 1; i < h - 1; i++) { + for (unsigned int i = 1; i < (h - 1); ++i) { GI[i][j] = vpImageFilter::filterGaussYPyramidal(I, 2 * i, j); } GI[h - 1][j] = I[2 * h - 1][j]; @@ -589,10 +598,13 @@ float vpImageFilter::median(const cv::Mat &channel) cv::Mat hist; cv::calcHist(&channel, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange, uniform, accumulate); - for (int i = 0; i < histSize && med < 0.0; ++i) { + int i = 0; + while ((i < histSize) && (med < 0.0f)) { bin += cvRound(hist.at(i)); - if (bin > m && med < 0.0) + if ((bin > m) && (med < 0.0f)) { med = static_cast(i); + } + ++i; } return med; @@ -629,7 +641,7 @@ std::vector vpImageFilter::median(const vpImage &Isrc) 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++) { + for (unsigned int i = 0; i < 3; ++i) { meds[orderMeds[i]] = median(channels[orderCvChannels[i]]); } return meds; @@ -664,7 +676,7 @@ float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p int bins = 256; cv::Mat dI, dIx, dIy, dIx_abs, dIy_abs; - if (p_cv_dIx == nullptr || p_cv_dIy == nullptr) { + if ((p_cv_dIx == nullptr) || (p_cv_dIy == nullptr)) { computePartialDerivatives(cv_I, dIx, dIy, true, true, true, gaussianKernelSize, gaussianStdev, apertureGradient, filteringType); } @@ -690,13 +702,13 @@ float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p bool accumulate = false; // Clear the histogram at the beginning of calcHist if false, does not clear it otherwise cv::calcHist(&dI, 1, channels, cv::Mat(), hist, dims, histSize, ranges, uniform, accumulate); float accu = 0; - float t = (float)(upperThresholdRatio * w * h); + float t = static_cast(upperThresholdRatio * w * h); float bon = 0; - for (int i = 0; i < bins; i++) { + for (int i = 0; i < bins; ++i) { float tf = hist.at(i); accu = accu + tf; if (accu > t) { - bon = (float)i; + bon = static_cast(i); break; } } @@ -728,8 +740,8 @@ void vpImageFilter::computePartialDerivatives(const cv::Mat &cv_I, const unsigned int &apertureGradient, const vpImageFilter::vpCannyFilteringAndGradientType &filteringType) { - if (filteringType == vpImageFilter::CANNY_GBLUR_SCHARR_FILTERING - || filteringType == vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING) { + if ((filteringType == vpImageFilter::CANNY_GBLUR_SCHARR_FILTERING) + || (filteringType == vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING)) { cv::Mat img_blur; // Apply Gaussian blur to the image cv::Size gsz(gaussianKernelSize, gaussianKernelSize); @@ -741,7 +753,7 @@ void vpImageFilter::computePartialDerivatives(const cv::Mat &cv_I, if (normalize) { scale = 1. / 8.; if (apertureGradient > 3) { - scale *= std::pow(1./2., (apertureGradient * 2. - 3.)); // 1 / 2^(2 x ksize - dx - dy -2) with ksize =apertureGradient and dx xor dy = 1 + scale *= std::pow(1./2., (static_cast(apertureGradient) * 2. - 3.)); // 1 / 2^(2 x ksize - dx - dy -2) with ksize =apertureGradient and dx xor dy = 1 } } if (computeDx) { @@ -1028,12 +1040,12 @@ void vpImageFilter::canny(const vpImage &Isrc, vpImage= 0x030200) @@ -1057,12 +1069,12 @@ void vpImageFilter::canny(const vpImage &Isrc, vpImage