CV_8U和CV_32F之间的区别是什么,当我们在它们之间转换时,我应该担心什么? [英] What are the differences between CV_8U and CV_32F and what should I worry about when converting between them?

查看:5947
本文介绍了CV_8U和CV_32F之间的区别是什么,当我们在它们之间转换时,我应该担心什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,我怀疑它是因为我操作错误类型的数据或它们之间的转换。



它是混合 cv :: Mat 类型的对象 CV_8U (这是使用 cv :: imread ), CV_32F 读取jpg为灰度时创建的 CV_32S



这些数据类型之间有什么区别,我需要确定什么时候转换

CV_8U是无符号的8位/像素 - 即像素可以具有值0-255,这是正常范围对于大多数图像和视频格式。



CV_32F是float - 像素可以有0-1.0之间的任何值,这对于一些数据集的计算很有用 - 必须通过将每个像素乘以255来转换为8bits以保存或显示。



CV_32S是每个像素的带符号32位整数值 - 数学在像素上,但仍需要转换为8位来保存或显示。这是棘手的,因为你需要决定如何将更大范围的可能值(+/- 2billion!)转换为0-255


I have some code that is acting up and I suspect it's because I'm operating on the wrong types of data or converting between them poorly.

It is mixing cv::Mat objects of types CV_8U (which is what is created when reading a jpg as grayscale with cv::imread), CV_32F, and CV_32S.

What are the differences between these data types, and what do I need to be sure of when converting between them?

解决方案

CV_8U is unsigned 8bit/pixel - ie a pixel can have values 0-255, this is the normal range for most image and video formats.

CV_32F is float - the pixel can have any value between 0-1.0, this is useful for some sets of calculations on data - but it has to be converted into 8bits to save or display by multiplying each pixel by 255.

CV_32S is a signed 32bit integer value for each pixel - again useful of you are doing integer maths on the pixels, but again needs converting into 8bits to save or display. This is trickier since you need to decide how to convert the much larger range of possible values (+/- 2billion!) into 0-255

这篇关于CV_8U和CV_32F之间的区别是什么,当我们在它们之间转换时,我应该担心什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆