saturate_cast<unsigned int> does not work as expected (Bug #2790)


Added by Pascal Thomet about 12 years ago. Updated about 12 years ago.


Status:Cancelled Start date:2013-02-09
Priority:Normal Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:2.4.4 Estimated time:1.00 hour
Affected version:2.4.3 Operating System:
Difficulty: HW Platform:
Pull request:

Description

cv::saturate_cast does not seem to work with unsigned int !
The following code :

void TestSaturateCast()
{
  double  d = -2.8;
  unsigned int val = cv::saturate_cast<unsigned int>(d);
  std::cout << "d = " << d << " val =" << val;
}

Will output :
d = -2.8 val =4294967293

My machine specs : Windows 7 32 bits, MSVC 2010, OpenCV 2.4.3,


Associated revisions

Revision 6952b90e
Added by Alexander Alekhin over 10 years ago

Merge pull request #2790 from akarsakov:ocl_pyrUp_unroll

History

Updated by Kirill Kornyakov about 12 years ago

Confirm that on my Ubuntu workstation I have the same result. But in operations.hpp you can find a note that such behavior is intentional:

// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.

So, I don't know why such decision was made, but this looks like "not a bug". Vadim, could you comment on that?

P.S. decided to document such behaviour in the form of unit test: https://github.com/Itseez/opencv/pull/468.

  • Category set to core
  • Target version set to 2.4.4
  • Assignee set to Vadim Pisarevsky
  • Status changed from Open to Cancelled

Updated by Vadim Pisarevsky about 12 years ago

we do not support 32-bit unsigned integers in OpenCV. If you look at our CV_8U ... CV_64F list - there is no CV_32U type there. I do not remember why we added saturate_cast<unsigned>(), probably to handle some template code, but you should not rely on it.

Also available in: Atom PDF