-3

A simple float cv::Mat like this

cv::Mat _1 = (cv::Mat_<float>(5, 5) << 1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, 36, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1); has that output after using cv::pow(_1,2,_1)

 [1, 16, 36, 16, 1;
 16, 256, 576, 256, 16;
 36, 576, 1296, 576, 36;
 16, 256, 576, 256, 16;
 1, 16, 36, 16, 1]


which is ok, but when using cv::cuda::pow(_1,2,_1) the output is

 [1, 16, 35.999996, 16, 1;
 16, 256, 575.99994, 256, 16;
 35.999996, 575.99994, 1295.9996, 575.99994, 35.999996;
 16, 256, 575.99994, 256, 16;
 1, 16, 35.999996, 16, 1]

What's the reason for that strange output ? also that problem is solved when using double instead of float but I want to know the reason of that

talonmies
  • 70,661
  • 34
  • 192
  • 269

1 Answers1

0

I suspect cv::gpu::pow implementation use floats for you pow value, and CPU implementations use a double, this is causing the imprecision on your results.

So your problem is due to the precision of the floating point representation. This problem is named ROUNDING ERROR.

Some usefull links : Why Are Floating Point Numbers Inaccurate? or http://faculty.tarleton.edu/agapie/documents/cs_343_arch/papers/1991_Goldberg_FloatingPoint.pdf

In short, it's happens because an integer can't always be exactly represented with a mantisse + exponent depending on your floating point type (half,float,double)

Community
  • 1
  • 1
X3liF
  • 1,054
  • 6
  • 10