opencv | cvtColor()

void cv::cvtColor(InputArray src,OutputArray dst,int code,int dstCn = 0)        

Python:dst=cv.cvtColor(src,code[, dst[, dstCn]])

Converts an image from one color space to another.
将图像从一个颜色空间转换为另一个颜色空间。

The function converts an input image from one color space to another. 
函数将输入图像从一个颜色空间转换为另一个颜色空间。
In case of a transformation to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). 
在从RGB颜色空间转换的情况下,应该明确指定信道的顺序(RGB或BGR)

Note that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the bytes are reversed). 
请注意,OpenCV中的默认颜色格式通常称为RGB,但实际上是BGR(字节被反转)。
So the first byte in a standard (24-bit) color image will be an 8-bit Blue component, the second byte will be Green, and the third byte will be Red. 
因此,标准(24位)彩色图像中的第一个字节将是一个8位蓝色分量,第二个字节将是绿色的,第三个字节将是红色。
The fourth, fifth, and sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.
第四、第五和第六字节将是第二像素(蓝色,然后是格林,然后是红色),等等。

The conventional ranges for R, G, and B channel values are:
R、G和B信道值的常规范围为:

0 to 255 for CV_8U images
0 to 65535 for CV_16U images
0 to 1 for CV_32F images

In case of linear transformations, the range does not matter. 
在线性变换的情况下,范围并不重要。
But in case of a non-linear transformation, an input RGB image should be normalized to the proper value range to get the correct results, for example, for RGB → L*u*v* transformation. 
输入RGB图像应该归一化到适当的取值范围,以获得正确的结果。例如,对于RGB->L*U*V*变换。
For example, if you have a 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will have the 0..255 value range instead of 0..1 assumed by the function. 
例如,如果您有一个32位浮点图像直接从8位图像转换而无任何缩放,那么它将具有0…255值范围,而不是由函数假定的0..1。
So, before calling cvtColor , you need first to scale the image down:
因此,在调用cvtColor之前,首先需要缩放图像:

img *= 1./255;
cvtColor(img, img, COLOR_BGR2Luv);

If you use cvtColor with 8-bit images, the conversion will have some information lost. 
如果以8位图像使用cvtColor,转换将有一些信息丢失。
For many applications, this will not be noticeable but it is recommended to use 32-bit images in applications that need the full range of colors or that convert an image before an operation and then convert back.
对于许多应用程序,这将是不明显的,但建议在需要全范围颜色的应用程序中使用32位图像,或者在操作之前转换图像,然后将其转换回。
If conversion adds the alpha channel, its value will set to the maximum of corresponding channel range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F.
如果转换添加alpha通道,则其值将设置为对应信道的最大值。

范围:255为CVY8U,65535为CVY16U,1用于CVY32 F。

Parameters
参数:
src    input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point.输入图像:8位无符号,16位无符号(CVY16UC…)或单精度浮点。
dst    output image of the same size and depth as src.输出图像与SRC的大小和深度相同。
code    color space conversion code (see ColorConversionCodes).颜色空间转换代码(见颜色转换代码)。
dstCn    number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code.目标图像中的信道数量;如果参数为0,则从src和代码自动导出信道数量。

猜你喜欢

转载自blog.csdn.net/qq_39419087/article/details/82142327
今日推荐