C++ CV_8UC3 和其他类型在 OpenCV 中代表什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27183946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does CV_8UC3 and the other types stand for in OpenCV?
提问by sashoalm
I was surprised when I couldn't find anything in OpenCV documentation describing - with words - what the various types stand for, and Googling wasn't much help either. I know that CV_8UC1 is gray-scale, but what does CV_8UC3 stand for? Is it RGB? Or YUV?
当我在 OpenCV 文档中找不到任何用文字描述各种类型代表的内容时,我感到很惊讶,而谷歌搜索也没有太大帮助。我知道 CV_8UC1 是灰度的,但是 CV_8UC3 代表什么?是RGB吗?还是YUV?
Also, what about the other definitions from types_c.h
(they also lack comments). Is there a pattern to what the naming convention is? Can I interpret from their names to what their features are, like colors, etc.?
另外,来自types_c.h
(他们也没有评论)的其他定义呢?命名约定有什么模式吗?我可以从他们的名字解释他们的特征是什么,比如颜色等?
#define CV_8UC1 CV_MAKETYPE(CV_8U,1)
#define CV_8UC2 CV_MAKETYPE(CV_8U,2)
#define CV_8UC3 CV_MAKETYPE(CV_8U,3)
#define CV_8UC4 CV_MAKETYPE(CV_8U,4)
#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
#define CV_8SC1 CV_MAKETYPE(CV_8S,1)
#define CV_8SC2 CV_MAKETYPE(CV_8S,2)
#define CV_8SC3 CV_MAKETYPE(CV_8S,3)
#define CV_8SC4 CV_MAKETYPE(CV_8S,4)
#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
#define CV_16UC1 CV_MAKETYPE(CV_16U,1)
#define CV_16UC2 CV_MAKETYPE(CV_16U,2)
#define CV_16UC3 CV_MAKETYPE(CV_16U,3)
#define CV_16UC4 CV_MAKETYPE(CV_16U,4)
#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
#define CV_16SC1 CV_MAKETYPE(CV_16S,1)
#define CV_16SC2 CV_MAKETYPE(CV_16S,2)
#define CV_16SC3 CV_MAKETYPE(CV_16S,3)
#define CV_16SC4 CV_MAKETYPE(CV_16S,4)
#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
#define CV_32SC1 CV_MAKETYPE(CV_32S,1)
#define CV_32SC2 CV_MAKETYPE(CV_32S,2)
#define CV_32SC3 CV_MAKETYPE(CV_32S,3)
#define CV_32SC4 CV_MAKETYPE(CV_32S,4)
#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
#define CV_32FC1 CV_MAKETYPE(CV_32F,1)
#define CV_32FC2 CV_MAKETYPE(CV_32F,2)
#define CV_32FC3 CV_MAKETYPE(CV_32F,3)
#define CV_32FC4 CV_MAKETYPE(CV_32F,4)
#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
#define CV_64FC1 CV_MAKETYPE(CV_64F,1)
#define CV_64FC2 CV_MAKETYPE(CV_64F,2)
#define CV_64FC3 CV_MAKETYPE(CV_64F,3)
#define CV_64FC4 CV_MAKETYPE(CV_64F,4)
#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
回答by Hannes Ovrén
As noted in the documentation
Any primitive type from the list can be defined by an identifier in the form
CV_<bit-depth>{U|S|F}C(<number_of_channels>)
列表中的任何原始类型都可以通过以下形式的标识符定义
CV_<bit-depth>{U|S|F}C(<number_of_channels>)
where U is unsigned integer type, S is signed integer type, and F is float type.
其中 U 是无符号整数类型,S 是有符号整数类型,F 是浮点类型。
so CV_8UC3
is an 8-bit unsigned integer matrix/image with 3 channels.
Although it is most common that this means an RGB (or actually BGR) image, it does not mandate it.
It simply means that there are three channels, and how you use them is up to you and your application.
所以CV_8UC3
是一个8位的无符号整数矩阵/ 3个通道的图像。虽然最常见的是这意味着 RGB(或实际上是 BGR)图像,但它并不强制要求。这只是意味着有三个通道,您如何使用它们取决于您和您的应用程序。
回答by sansuiso
The naming pattern depicts how the data is actually laid out in the PC memory and is not directly related to the image type. Actually, data layout and image type are decoupled.
命名模式描述了数据在 PC 内存中的实际布局方式,与图像类型没有直接关系。实际上,数据布局和图像类型是解耦的。
You have probably found out the meaning for the CV_XX pattern (ie, data layout).
您可能已经发现了 CV_XX 模式(即数据布局)的含义。
For the imaged data type, if you ask OpenCV to load an image as a colour image, it will load it as a BGRimage and lay out its data as CV_8UC3. A few things to be aware of:
对于图像数据类型,如果您要求 OpenCV 将图像加载为彩色图像,它将加载为BGR图像并将其数据布局为 CV_8UC3。需要注意的几点:
- yes, the default channel ordering is BGRand not RGB. This is a legacy ordering because digital video feeds from webcams seemed to follow this order when OpenCV 1.xx was under development;
- you can use type conversion functions from the module
imgproc
, namelycv::cvtColor()
. All data layouts and image types are not compatible though, check the doc; - the alpha channel is usually ignored. By ignoring, I mean that
cv::imwrite()
will write a 3 channel image without alpha for example. Most of the processing functions will either be specific to single channel images or apply the same processing to all the channels equally; - when a function accepts an (alpha-)mask, it is usually an optional parameter of type
CV_8UC1
that defaults to an empty matrix.
- 是的,默认通道顺序是BGR而不是RGB。这是一个传统的顺序,因为在开发 OpenCV 1.xx 时,来自网络摄像头的数字视频源似乎遵循这个顺序;
- 您可以使用模块中的类型转换函数
imgproc
,即cv::cvtColor()
. 但是,所有数据布局和图像类型都不兼容,请查看文档; - alpha 通道通常被忽略。忽略,我的意思是
cv::imwrite()
将编写一个没有 alpha 的 3 通道图像。大多数处理功能要么特定于单通道图像,要么对所有通道均等地应用相同的处理; - 当一个函数接受一个(alpha-)掩码时,它通常是一个
CV_8UC1
默认为空矩阵类型的可选参数。
回答by Giant Cloud
8UC3 helps you access the RGB data. And it is not limited to just images. You can use it for accessing the RGB data in Point Clouds as well. If you pass the RGB value as a Matrix of type 8UC3, you can then show this value as color in the viz module and display an RGB Pointcloud.
8UC3 可帮助您访问 RGB 数据。它不仅限于图像。您也可以使用它来访问点云中的 RGB 数据。如果将 RGB 值作为 8UC3 类型的矩阵传递,则可以在 viz 模块中将此值显示为颜色并显示 RGB 点云。