saturate_cast<>()

saturate_cast

Template function for accurate conversion from one primitive type to another.
C++:template<…> _Tpsaturate_cast(_Tp2v)¶
Parameters:
v – Function parameter.
The functions saturate_cast resemble the standard C++ cast operations, such asstatic_cast() and others. They perform an efficient and accurate conversion from one primitive type to another (see the introduction chapter).saturate in the name means that when the input valuev is out of the range of the target type, the result is not formed just by taking low bits of the input, but instead the value is clipped. For example:

uchar a = saturate_cast(-100); // a = 0 (UCHAR_MIN)
short b = saturate_cast(33333.33333); // b = 32767 (SHRT_MAX)
Such clipping is done when the target type is unsignedchar ,signedchar ,unsignedshort orsignedshort . For 32-bit integers, no clipping is done.

When the parameter is a floating-point value and the target type is an integer (8-, 16- or 32-bit), the floating-point value is first rounded to the nearest integer and then clipped if needed (when the target type is 8- or 16-bit).

This operation is used in the simplest or most complex image processing functions in OpenCV.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值