非 8 位系统上的 CV_8U opencv 矩阵
我读到,signed char 和 unsigned char 类型不能保证在每个平台上都是 8 位,但有时它们有超过 8 位。 如果是这样,使用 OpenCv 我们如何确定 CV_8U 始终是 8 位? 我编写了一个简短的函数,它采用 8 位 Mat,并且如果需要的话,会将 CV_8SC1 Mat 元素转换为 uchar,将 CV_8UC1 转换为 schar。 现在我担心它不是独立于平台的,我应该以某种方式修复代码(但不知道如何)。
PS:同样,CV_32S 如何总是 int,即使在没有 32 位 int 的机器上?
I've read that the signed char and unsigned char types are not guaranteed to be 8 bits on every platform, but sometimes they have more than 8 bits.
If so, using OpenCv how can we be sure that CV_8U is always 8bit?
I've written a short function which takes a 8 bit Mat and happens to convert, if needed, CV_8SC1 Mat elements into uchars and CV_8UC1 into schar.
Now I'm afraid it is not platform independent an I should fix the code in some way (but don't know how).
P.S.: Similarly, how can CV_32S always be int, also on machine with no 32bit ints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能提供一下参考吗(我从未听说过)?可能您的意思是可以在 cv::Mat 中的行末尾添加的填充。这没有问题,因为通常不使用填充,特别是如果您使用接口函数,例如迭代器(cf)。如果您发布一些代码,我们可以看到您的实现是否确实存在此类问题。
CV_32S
将始终为 32 位整数,因为它们使用inttypes.h
中定义的类型(例如int32_t
、uint32_t< /code>),而不是特定于平台的
int
、long
等。Can you give a reference of this (I've never heard of that)? Probably you mean the padding that may be added at the end of a row in a cv::Mat. That is of no problem, since the padding is usually not used, and especially no problem if you use the interface functions, e.g. the iterators (c.f.). If you would post some code, we could see, if your implementation actually had such problems.
the
CV_32S
will be always 32-bit integer because they use types like those defined ininttypes.h
(e.g.int32_t
,uint32_t
) and not the platform specificint
,long
, whatever.