[python]OpenCV之cvtColor

官方文档:https://docs.opencv.org/ 


cvCvtColor是Opencv里的颜色空间转换函数

最常见的就是实现灰度转化HSV转化

 

官方文档的解释:

§ cvtColor()

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

Parameters(参数)

src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point.
dst output image of the same size and depth as 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.

 可以看到cvtColor的参数并不复杂

cvtColor(src,dst,code,dstCn)  ===>  (原图像,输出图像,color转化代码,输出通道) 

1,原图像:input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point.,解释的很清楚8位无符号,16位无符号,或者单精浮点数。

2,输出图像:output image of the same size and depth as src. 输出与src相同大小和深度的图像。

3,code :color转化代码

COLOR_BGR2BGRA 

Python: cv.COLOR_BGR2BGRA

add alpha channel to RGB or BGR image(为rgb或bgr增加alpha通道)

COLOR_RGB2RGBA 

Python: cv.COLOR_RGB2RGBA

COLOR_BGRA2BGR 

Python: cv.COLOR_BGRA2BGR

remove alpha channel from RGB or BGR image(为rgb或bgr移除alpha通道)

COLOR_RGBA2RGB 

Python: cv.COLOR_RGBA2RGB

 

COLOR_BGR2GRAY 

Python: cv.COLOR_BGR2GRAY

convert between RGB/BGR and grayscale, color conversions

COLOR_RGB2GRAY 

Python: cv.COLOR_RGB2GRAY

 
COLOR_GRAY2BGR 

Python: cv.COLOR_GRAY2BGR

 
COLOR_GRAY2RGB 

Python: cv.COLOR_GRAY2RGB

 

COLOR_BGR2HSV 

Python: cv.COLOR_BGR2HSV

convert RGB/BGR to HSV (hue saturation value), color conversions

COLOR_RGB2HSV 

Python: cv.COLOR_RGB2HSV

 

更多转化code,前往https://docs.opencv.org/trunk/d8/d01/group__imgproc__color__conversions.html#gga4e0972be5de079fed4e3a10e24ef5ef0aa4f6bc658bc546e1660fcab6bf7858f4查看

4,通道数:一般不写 ,参数说明number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code.  会自动根据src和code来自动导出通道数

 

实际使用:

cv.cvtColor(src, dst, cv.COLOR_RGB2HSV); //转为hsv图

 

你可能感兴趣的:(python3,图像处理(OpenCV))