From db5850666d6961d2f274a1b8175c2f444cff27a5 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 4 Nov 2024 10:07:36 +0100 Subject: [PATCH] Fix segfault when printings statistics. The following segfault was detected on Apple M1 Pro, while there is no segfault on CI! There was an out of range memory access to computation_times vector. % ./tutorial-compare-auto-gamma --input Sample_low_brightness.png --output Results/cube Input: Sample_low_brightness.png Process on half image resolution? 0 Gaussian kernel size: 3 Gaussian standard deviation: 1 Aperture size: 3 Canny filtering type: 0 RGB colorspace? 0 Output result folder: Results/cube Computation time (gamma_log): 2.30396 ms Computation time (gamma_nonlinear): 1.27197 ms Computation time (gamma_cdf): 2.1228 ms Computation time (gamma_classification): 2.62817 ms Computation time (gamma_spatial_variant): 19.5791 ms Write result to: Results/cube/Sample_low_brightness.jpeg Stats: Nb images: 1 gamma_log: mean=2.1228 ms ; median=2.1228 ms gamma_nonlinear: mean=2.62817 ms ; median=2.62817 ms gamma_cdf: mean=19.5791 ms ; median=19.5791 ms libc++abi: terminating due to uncaught exception of type vpException: Empty vector ! --- .../imgproc/brightness/tutorial-compare-auto-gamma.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tutorial/imgproc/brightness/tutorial-compare-auto-gamma.cpp b/tutorial/imgproc/brightness/tutorial-compare-auto-gamma.cpp index b9d9c98055..f25acdc3e8 100755 --- a/tutorial/imgproc/brightness/tutorial-compare-auto-gamma.cpp +++ b/tutorial/imgproc/brightness/tutorial-compare-auto-gamma.cpp @@ -49,8 +49,8 @@ void computeMeanMaxStdev(const vpImage &I, float &mean, float &max, float &st } void computeCanny(const vpImage &I, vpCannyEdgeDetection &cannyDetector, int gaussianKernelSize, - float gaussianStdev, int apertureSize, vpImageFilter::vpCannyFilteringAndGradientType filteringType, - vpImage &dIxy_uchar, vpImage &I_canny_visp) + float gaussianStdev, int apertureSize, vpImageFilter::vpCannyFilteringAndGradientType filteringType, + vpImage &dIxy_uchar, vpImage &I_canny_visp) { vpImage dIx, dIy, dIxy(I.getHeight(), I.getWidth()); vpImageFilter::computePartialDerivatives(I, dIx, dIy, true, true, true, gaussianKernelSize, gaussianStdev, @@ -304,8 +304,8 @@ int main(int argc, const char **argv) continue; } std::cout << VISP_NAMESPACE_NAME::vpGammaMethodToString(gamma_method) << ": mean=" - << vpMath::getMean(computation_times[gamma_idx+1]) << " ms ; median=" - << vpMath::getMedian(computation_times[gamma_idx+1]) << " ms" << std::endl; + << vpMath::getMean(computation_times[gamma_idx-1]) << " ms ; median=" + << vpMath::getMedian(computation_times[gamma_idx-1]) << " ms" << std::endl; } return EXIT_SUCCESS;