From 137454d8b8115de81726140685fa6a353aad62ab Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Fri, 12 Jan 2024 16:15:26 +0100 Subject: [PATCH] Fix warnings detected with msvc17, mainly cast issues --- modules/core/include/visp3/core/vpImageFilter.h | 6 +++--- modules/core/src/image/vpImageCircle.cpp | 16 ++++++++-------- modules/core/src/image/vpImageFilter.cpp | 2 +- .../imgproc/include/visp3/imgproc/vpContours.h | 2 ++ modules/imgproc/src/vpCircleHoughTransform.cpp | 6 +++--- .../pololu-maestro/vpRobotPololuPtu.cpp | 14 +++++++------- .../test/servo-pololu/testPololuPosition.cpp | 6 +++--- .../test/servo-pololu/testPololuVelocity.cpp | 6 +++--- tutorial/image/tutorial-canny.cpp | 12 ++++++------ .../hough-transform/tutorial-circle-hough.cpp | 6 +++--- 10 files changed, 39 insertions(+), 37 deletions(-) diff --git a/modules/core/include/visp3/core/vpImageFilter.h b/modules/core/include/visp3/core/vpImageFilter.h index aabada47f6..560c79b673 100644 --- a/modules/core/include/visp3/core/vpImageFilter.h +++ b/modules/core/include/visp3/core/vpImageFilter.h @@ -294,8 +294,8 @@ class VISP_EXPORT vpImageFilter const float &lowerThresholdRatio = 0.6, const float &upperThresholdRatio = 0.8, const vpCannyFilteringAndGradientType &filteringType = CANNY_GBLUR_SOBEL_FILTERING) { - double w = I.getWidth(); - double h = I.getHeight(); + unsigned int w = static_cast(I.getWidth()); + unsigned int h = static_cast(I.getHeight()); vpImage dI(h, w); vpImage dIx(h, w), dIy(h, w); @@ -327,7 +327,7 @@ class VISP_EXPORT vpImageFilter float t = (float)(upperThresholdRatio * w * h); float bon = 0; for (unsigned int i = 0; i < nbBins; ++i) { - float tf = hist[i]; + float tf = static_cast(hist[i]); accu = accu + tf; if (accu > t) { bon = (float)i; diff --git a/modules/core/src/image/vpImageCircle.cpp b/modules/core/src/image/vpImageCircle.cpp index 39db6b75d9..5ac5933ae6 100644 --- a/modules/core/src/image/vpImageCircle.cpp +++ b/modules/core/src/image/vpImageCircle.cpp @@ -910,16 +910,16 @@ float vpImageCircle::computeAngularCoverageInRoI(const vpRect &roi, const float { float delta_theta = 0.f; vpImagePoint center = m_center; - float u_c = center.get_u(); - float v_c = center.get_v(); + float u_c = static_cast(center.get_u()); + float v_c = static_cast(center.get_v()); float radius = m_radius; - float roi_w = roi.getWidth(); - float roi_h = roi.getHeight(); + float roi_w = static_cast(roi.getWidth()); + float roi_h = static_cast(roi.getHeight()); vpImagePoint topLeft = roi.getTopLeft(); - float umin_roi = topLeft.get_u(); - float vmin_roi = topLeft.get_v(); - float umax_roi = topLeft.get_u() + roi_w; - float vmax_roi = topLeft.get_v() + roi_h; + float umin_roi = static_cast(topLeft.get_u()); + float vmin_roi = static_cast(topLeft.get_v()); + float umax_roi = umin_roi + roi_w; + float vmax_roi = vmin_roi + roi_h; bool touchLeftBorder = (u_c - radius) <= umin_roi; bool touchRightBorder = (u_c + radius) >= umax_roi; bool touchTopBorder = (v_c - radius) <= vmin_roi; diff --git a/modules/core/src/image/vpImageFilter.cpp b/modules/core/src/image/vpImageFilter.cpp index 3d76af9339..36fa00d62a 100644 --- a/modules/core/src/image/vpImageFilter.cpp +++ b/modules/core/src/image/vpImageFilter.cpp @@ -1075,7 +1075,7 @@ void vpImageFilter::canny(const vpImage &Isrc, vpImage(peak_positions_votes.size()); if (nbPeaks > 0) { std::vector has_been_merged(nbPeaks, false); std::vector, float>> merged_peaks_position_votes; @@ -672,7 +672,7 @@ vpCircleHoughTransform::computeCenterCandidates() std::sort(merged_peaks_position_votes.begin(), merged_peaks_position_votes.end(), sortingCenters); - nbPeaks = merged_peaks_position_votes.size(); + nbPeaks = static_cast(merged_peaks_position_votes.size()); int nbPeaksToKeep = (m_algoParams.m_expectedNbCenters > 0 ? m_algoParams.m_expectedNbCenters : nbPeaks); nbPeaksToKeep = std::min(nbPeaksToKeep, (int)nbPeaks); for (int i = 0; i < nbPeaksToKeep; i++) { @@ -793,7 +793,7 @@ vpCircleHoughTransform::computeCircleCandidates() } } - unsigned int nbCandidates = v_r_effective.size(); + unsigned int nbCandidates = static_cast(v_r_effective.size()); for (unsigned int idBin = 0; idBin < nbCandidates; ++idBin) { // If the circle of center CeC_i and radius RCB_k has enough votes, it is added to the list // of Circle Candidates diff --git a/modules/robot/src/real-robot/pololu-maestro/vpRobotPololuPtu.cpp b/modules/robot/src/real-robot/pololu-maestro/vpRobotPololuPtu.cpp index f6dabef9e8..be3c57a42c 100644 --- a/modules/robot/src/real-robot/pololu-maestro/vpRobotPololuPtu.cpp +++ b/modules/robot/src/real-robot/pololu-maestro/vpRobotPololuPtu.cpp @@ -47,12 +47,12 @@ vpRobotPololuPtu::vpRobotPololuPtu(const std::string &device, int baudrate, bool nDof = 2; m_pan.connect(device, baudrate, 0); m_pan.setPwmRange(4095, 7905); - m_pan.setAngularRange(vpMath::rad(-45), vpMath::rad(45)); + m_pan.setAngularRange(static_cast(vpMath::rad(-45)), static_cast(vpMath::rad(45))); m_pan.setVerbose(verbose); m_tilt.connect(device, baudrate, 1); m_tilt.setPwmRange(4095, 7905); - m_tilt.setAngularRange(vpMath::rad(-45), vpMath::rad(45)); + m_tilt.setAngularRange(static_cast(vpMath::rad(-45)), static_cast(vpMath::rad(45))); m_tilt.setVerbose(verbose); } @@ -151,9 +151,9 @@ void vpRobotPololuPtu::setPosition(const vpRobot::vpControlFrameType frame, cons break; } - float pos_vel = m_positioning_velocity_percentage * getMaxRotationVelocity(); - m_pan.setAngularPosition(q[0], pos_vel); - m_tilt.setAngularPosition(q[1], pos_vel); + float pos_vel = m_positioning_velocity_percentage * static_cast(getMaxRotationVelocity()); + m_pan.setAngularPosition(static_cast(q[0]), pos_vel); + m_tilt.setAngularPosition(static_cast(q[1]), pos_vel); } void vpRobotPololuPtu::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) @@ -227,8 +227,8 @@ void vpRobotPololuPtu::setVelocity(const vpRobot::vpControlFrameType frame, cons std::cout << "Send velocity: " << q_dot_sat.t() << std::endl; - m_pan.setAngularVelocity(q_dot_sat[0]); - m_tilt.setAngularVelocity(q_dot_sat[1]); + m_pan.setAngularVelocity(static_cast(q_dot_sat[0])); + m_tilt.setAngularVelocity(static_cast(q_dot_sat[1])); } vpRobot::vpRobotStateType vpRobotPololuPtu::setRobotState(vpRobot::vpRobotStateType newState) diff --git a/modules/robot/test/servo-pololu/testPololuPosition.cpp b/modules/robot/test/servo-pololu/testPololuPosition.cpp index 0e4799f93f..3b49043c98 100644 --- a/modules/robot/test/servo-pololu/testPololuPosition.cpp +++ b/modules/robot/test/servo-pololu/testPololuPosition.cpp @@ -103,9 +103,9 @@ int main(int argc, const char **argv) bool opt_calibrate = false; unsigned short opt_pwm_min = 4000; unsigned short opt_pwm_max = 8000; - float opt_angle_min = vpMath::rad(-45); - float opt_angle_max = vpMath::rad(45); - float opt_positioning_velocity = vpMath::rad(10); + float opt_angle_min = static_cast(vpMath::rad(-45)); + float opt_angle_max = static_cast(vpMath::rad(45)); + float opt_positioning_velocity = static_cast(vpMath::rad(10)); float last_angle = 0; int time_s = 0; diff --git a/modules/robot/test/servo-pololu/testPololuVelocity.cpp b/modules/robot/test/servo-pololu/testPololuVelocity.cpp index d9224a5f13..7d9610b4ad 100644 --- a/modules/robot/test/servo-pololu/testPololuVelocity.cpp +++ b/modules/robot/test/servo-pololu/testPololuVelocity.cpp @@ -101,9 +101,9 @@ int main(int argc, const char **argv) bool opt_calibrate = false; unsigned short opt_pwm_min = 4000; unsigned short opt_pwm_max = 8000; - float opt_angle_min = vpMath::rad(-45); - float opt_angle_max = vpMath::rad(45); - float opt_velocity = vpMath::rad(5); + float opt_angle_min = static_cast(vpMath::rad(-45)); + float opt_angle_max = static_cast(vpMath::rad(45)); + float opt_velocity = static_cast(vpMath::rad(5)); float last_angle = 0; for (int i = 1; i < argc; i++) { diff --git a/tutorial/image/tutorial-canny.cpp b/tutorial/image/tutorial-canny.cpp index f11301bf5e..94d1aab72e 100644 --- a/tutorial/image/tutorial-canny.cpp +++ b/tutorial/image/tutorial-canny.cpp @@ -49,7 +49,7 @@ void computeMeanMaxStdev(const vpImage &I, float &mean, float &max, float &st stdev = 0.; unsigned int nbRows = I.getRows(); unsigned int nbCols = I.getCols(); - float scale = 1. / ((float)nbRows * (float)nbCols); + float scale = 1.f / (static_cast(nbRows) * static_cast(nbCols)); for (unsigned int r = 0; r < nbRows; r++) { for (unsigned int c = 0; c < nbCols; c++) { mean += I[r][c]; @@ -178,12 +178,12 @@ int main(int argc, const char *argv[]) else if ((argv_str == "-g" || argv_str == "--gradient") && i + 2 < argc) { opt_gradientOutsideClass = true; opt_gaussianKernelSize = atoi(argv[i + 1]); - opt_gaussianStdev = atoi(argv[i + 2]); + opt_gaussianStdev = static_cast(atof(argv[i + 2])); i += 2; } else if ((argv_str == "-t" || argv_str == "--thresh") && i + 2 < argc) { - opt_lowerThresh = atof(argv[i + 1]); - opt_upperThresh = atof(argv[i + 2]); + opt_lowerThresh = static_cast(atof(argv[i + 1])); + opt_upperThresh = static_cast(atof(argv[i + 2])); i += 2; } else if ((argv_str == "-a" || argv_str == "--aperture") && i + 1 < argc) { @@ -195,8 +195,8 @@ int main(int argc, const char *argv[]) i++; } else if ((argv_str == "-r" || argv_str == "--ratio") && i + 2 < argc) { - opt_lowerThreshRatio = std::atof(argv[i + 1]); - opt_upperThreshRatio = std::atof(argv[i + 2]); + opt_lowerThreshRatio = static_cast(std::atof(argv[i + 1])); + opt_upperThreshRatio = static_cast(std::atof(argv[i + 2])); i += 2; } else if ((argv_str == "-b" || argv_str == "--backend") && i + 1 < argc) { diff --git a/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp b/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp index d89f7bcb51..5e2fb6beee 100644 --- a/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp +++ b/tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp @@ -191,11 +191,11 @@ int main(int argc, char **argv) i++; } else if (argName == "--lower-canny-ratio" && i + 1 < argc) { - opt_lowerCannyThreshRatio = atof(argv[i + 1]); + opt_lowerCannyThreshRatio = static_cast(atof(argv[i + 1])); i++; } else if (argName == "--upper-canny-ratio" && i + 1 < argc) { - opt_upperCannyThreshRatio = atof(argv[i + 1]); + opt_upperCannyThreshRatio = static_cast(atof(argv[i + 1])); i++; } else if (argName == "--expected-nb-centers" && i + 1 < argc) { @@ -247,7 +247,7 @@ int main(int argc, char **argv) std::cout << "DESCRIPTION" << std::endl << "\t--input" << std::endl << "\t\tPermit to choose the input of the Hough Circle Algorithm." << std::endl - << "\t\tIf you want to use a succession of images as video, their name must be in the format ${BASENAME}\%d.{jpg, png}." << std::endl + << "\t\tIf you want to use a succession of images as video, their name must be in the format ${BASENAME}%d.{jpg, png}." << std::endl << "\t\tDefault: " << def_input << std::endl << std::endl #ifdef VISP_HAVE_NLOHMANN_JSON