标签:pixel fill 输入 text lsp camshift tin 导出 void
1 CvtColor 2 Void cv::cvtColor(InputArray src, 3 OutputArray dst, 4 INT code, 5 INT dstCn =0 6 ) 7
将图像从一个颜色空间转换为另一个。
该函数将输入图像从一个颜色空间转换为另一个颜色空间。在从RGB颜色空间转换的情况下,应明确指定通道的顺序(RGB或BGR)。请注意,OpenCV中的默认颜色格式通常称为RGB,但实际上是BGR(字节相反)。因此,标准(24位)彩色图像中的第一个字节将为8位蓝色分量,第二个字节为绿色,第三个字节为红色。第四,第五和第六个字节将是第二个像素(蓝色,然后是绿色,然后是红色),依此类推。
R,G和B通道值的常规范围是:
在线性变换的情况下,范围无关紧要。但是在非线性变换的情况下,输入RGB图像应该被归一化到适当的值范围,以获得正确的结果,例如RGB →L * u * v *转换。例如,如果您有一个32位浮点图像直接从8位图像转换而不进行任何缩放,那么它将具有0..255的值范围而不是该函数假定的0..1。所以,在调用cvtColor之前,您需要先将图像缩小:
1 img * = 1./255; 2 cvtColor(img,img,COLOR_BGR2Luv);
如果您使用cvtColor与8位图像,转换将有一些信息丢失。对于许多应用程序,这并不会引人注目,但建议在需要全部颜色的应用程序中使用32位图像,或者在操作之前转换图像然后转换。
如果转换添加了Alpha通道,其值将设置为相应通道范围的最大值:CV_8U为255,CV_16U为65535,CV_32F为1。
参数
SRC |
输入图像:8位无符号,16位无符号(CV_16UC ...)或单精度浮点。 |
DST |
输出与src相同大小和深度的图像。 |
code |
颜色空间转换代码(见cv :: ColorConversionCodes)。 |
dstCn |
目的地图像中的频道数; 如果参数为0,则从src和代码自动导出通道数。 |
也可以看看
例子:
camshiftdemo.cpp,edge.cpp,facedetect.cpp,ffilldemo.cpp,houghcircles.cpp,houghlines.cpp,lkdemo.cpp和watershed.cpp。
转换模式
RGB模式增加移除alpha通道、改变通道顺序、和16位RGB色彩模式(R5:G6:B5 或者 R5:G5:B5)的图像之间的转换、和灰度图之间的转换:
RGB[A] to Gray:Y←0.299?R+0.587?G+0.114?B
和
Gray to RGB[A]:R←Y,G←Y,B←Y,A←max(ChannelRange)
示例:
1 cvtColor(src, bwsrc, cv::COLOR_RGB2GRAY);
高级用法见cv::mixChannels
或者
cv::COLOR_BGR2GRAY, cv::COLOR_RGB2GRAY, cv::COLOR_GRAY2BGR, cv::COLOR_GRAY2RGB
X, Y and Z cover the whole value range (in case of floating-point images, Z may exceed 1).what’s the meaning of this sentence?
用法见:
cv::COLOR_BGR2XYZ, cv::COLOR_RGB2XYZ, cv::COLOR_XYZ2BGR, cv::COLOR_XYZ2RGB
其中
Y, Cr, and Cb cover the whole value range.
用法见:
cv::COLOR_BGR2YCrCb, cv::COLOR_RGB2YCrCb, cv::COLOR_YCrCb2BGR, cv::COLOR_YCrCb2RGB
在8位和16位图像的情况下,R,G和B将转换为浮点格式并缩放以适合0到1的范围。
用法见:
cv::COLOR_BGR2HSV, cv::COLOR_RGB2HSV, cv::COLOR_HSV2BGR, cv::COLOR_HSV2RGB
In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
用法见:
cv::COLOR_BGR2HLS, cv::COLOR_RGB2HLS, cv::COLOR_HLS2BGR, cv::COLOR_HLS2RGB
In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
用法见:
cv::COLOR_BGR2Lab, cv::COLOR_RGB2Lab, cv::COLOR_Lab2BGR, cv::COLOR_Lab2RGB
In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit 0 to 1 range.
The above formulae for converting RGB to/from various color spaces have been taken from multiple sources on the web, primarily from the Charles Poynton site http://www.poynton.com/ColorFAQ.html
用法见:
cv::COLOR_BGR2Luv, cv::COLOR_RGB2Luv, cv::COLOR_Luv2BGR, cv::COLOR_Luv2RGB
The Bayer pattern is widely used in CCD and CMOS cameras. It enables you to get color pictures from a single plane where R,G, and B pixels (sensors of a particular component) are interleaved as follows:
The output RGB components of a pixel are interpolated from 1, 2, or 4 neighbors of the pixel having the same color. There are several modifications of the above pattern that can be achieved by shifting the pattern one pixel left and/or one pixel up. The two letters C and C in the conversion constants CV_Bayer C1C2 2BGR and CV_Bayer C1C2 2RGB indicate the particular pattern type. These are components from the second row, second and third columns, respectively. For example, the above pattern has a very popular "BG" type.
用法见:
cv::COLOR_BayerBG2BGR, cv::COLOR_BayerGB2BGR, cv::COLOR_BayerRG2BGR, cv::COLOR_BayerGR2BGR,
cv::COLOR_BayerBG2RGB, cv::COLOR_BayerGB2RGB, cv::COLOR_BayerRG2RGB, cv::COLOR_BayerGR2RGB
标签:pixel fill 输入 text lsp camshift tin 导出 void
原文地址:http://www.cnblogs.com/anqiang1995/p/7442984.html