def cvtColor(src, code, dst=None, dstCn=None): # real signature unknown; restored from __doc__"""cvtColor(src, code[, dst[, dstCn]]) -> dst.   @brief 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). Note.   that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the.   bytes are reversed). 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. The fourth, fifth, and.   sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.该功能将输入图像从一种颜色空间转换为另一种颜色空间。 在从RGB颜色空间转换的情况下,应明确指定通道的顺序(RGB或BGR)。 请注意,OpenCV中的默认颜色格式通常称为RGB,但实际上是BGR(字节是相反的)。 因此,标准(24位)彩色图像中的第一个字节将是8位蓝色分量,第二个字节将是绿色分量,第三个字节将是红色分量。 第四,第五和第六个字节将是第二个像素(蓝色,然后是绿色,然后是红色),依此类推。.   .   The conventional ranges for R, G, and B channel values are:.   -   0 to 255 for CV_8U images.   -   0 to 65535 for CV_16U images.   -   0 to 1 for CV_32F imagesR,G和B通道值的常规范围是:。 -CV_8U图像为0至255。 -CV_16U图像为0至65535。 -CV_32F图像为0到1.   .   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 \f$\rightarrow\f$ L\*u\*v\* transformation. 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. So, before calling #cvtColor ,.   you need first to scale the image down:.   @code.   img *= 1./255;.   cvtColor(img, img, COLOR_BGR2Luv);.   @endcode.   If you use #cvtColor with 8-bit images, the conversion will have some information lost. 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..   在线性变换的情况下,范围无关紧要。 但是在进行非线性变换的情况下,应将输入的RGB图像规范化为适当的值范围以获得正确的结果,例如,对于RGB \ f $ \ rightarrow \ f $ L \ * u \ * v \ * 转型。 例如,如果您有一个32位浮点图像直接从8位图像转换而没有任何缩放,则它将具有0..255的值范围,而不是该函数假定的0..1。 因此,在调用#cvtColor之前,您需要先按比例缩小图像:。 @代码。 img * = 1./255;。 cvtColor(img,img,COLOR_BGR2Luv);。 @endcode。 如果将#cvtColor与8位图像一起使用,转换将丢失一些信息。 对于许多应用程序来说,这不会引起注意,但是建议在需要全彩范围的应用程序中使用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通道,则其值将设置为相应通道范围的最大值:CV_8U为255,CV_16U为65535,CV_32F为1。.   .   @param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision.   floating-point.输入图像:8位无符号,16位无符号(CV_16UC ...)或单精度浮点。.   @param dst output image of the same size and depth as src.输出图像:与src具有相同大小和深度。.   @param code color space conversion code (see #ColorConversionCodes).颜色空间转换代码(请参见#ColorConversionCodes)。.   @param 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和code得出。.   .   @see @ref imgproc_color_conversions"""pass

示例:

# -*- coding: utf-8 -*-
"""
@File    : 191213_测试_阈值分割.py
@Time    : 2019/12/13 15:14
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
import cv2 as cv# 【读取图像】
image = cv.imread('feiji.jpg')
# 【将图像灰度化】
image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
# 【显示图像】
cv.imshow('win', image)
cv.waitKey(0)

原图:

处理后:

参考文章:python opencv ColorConversionCodes

python opencv cv2.cvtColor()方法(将图像从一种颜色空间转换为另一种颜色空间)(转换成灰度图)相关推荐

  1. Intel Realsense D435 opencv 为什么将color图转换成灰度图后,再与depth图水平堆叠,其结果一片黑色?(数据未map到0-255)

    相关代码 # -*- coding: utf-8 -*- """ @File : obstacle_detection.py @Time : 2019/12/11 10: ...

  2. Windows Forms:在C#中将图像转换成灰度图

    Windows Forms:在C#中将图像转换成灰度图 本文翻译自Windows Forms: Convert an image into grayscale in C# 这篇文章向你展示在C# Wi ...

  3. Python OpenCV cv2缩放后合成图像有毛边

    文章目录 问题描述 解决方案 参考文献 问题描述 cv2缩放(放大和缩小)后合成的图像有毛边 1.png 2.png import cv2 from PIL import Imageimage = c ...

  4. 利用OpenCV把一幅彩色图像转换成灰度图

    图像灰度化的目的是为了简化矩阵,提高运算速度. 彩色图像中的每个像素颜色由R.G.B三个分量来决定,而每个分量的取值范围都在0-255之间,这样对计算机来说,彩色图像的一个像素点就会有256*256* ...

  5. opencv:把三通道图转换成灰度图、二值图

    #include <opencv2/core/core.hpp> #include<opencv2/highgui/highgui.hpp> #include<openc ...

  6. Python+OpenCV图像处理(五)——图像阈值和二值化

    系列文章 Python+OpenCV图像处理(一)--OpenCV框架与图像插值算法 Python+OpenCV图像处理(二)--几何变换 Python+OpenCV图像处理(三)--彩色空间互换 P ...

  7. python opencv cv2.imread

    python opencv cv2.imread 环境说明 opencv 安装 pip install opencv-python opencv:opencv_python 4.5.5.64 介绍 方 ...

  8. python opencv cv2在图片中画mask掩码/掩膜

    python opencv cv2在图片中画mask掩膜 import cv2 import numpy as np from PIL import Image import matplotlib.p ...

  9. 计算机系统的图形图像编码方式,只有将数字、文字、图像、声音和视频等不同类型的信息转换成_______代码,才便于计算机加工和处理。...

    只有将数字.文字.图像.声音和视频等不同类型的信息转换成_______代码,才便于计算机加工和处理.以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容, ...

最新文章

  1. 多次执行echarts时出现 there is a chart instance already initialized on the dom
  2. 中职学校的学生计算机基础较弱,中职学校计算机专业教学的现状分析及对策探究.doc...
  3. Spring Cloud:Eureka Server控制台
  4. P3586-[POI2015]LOG【线段树】
  5. 对照片进行边缘化处理,并将边缘化处理后的结果保存
  6. 工作总结22:拦截器
  7. ThreadPoolExecutor源码学习(2)-- 在thrift中的应用
  8. 第一款Micropython图形化编辑器—Python Editor
  9. C++库研究笔记——Linux下是否需要使用memory pool?
  10. embedding与pytorch中squeeze()和unsqueeze()函数介绍
  11. HTML中段落标签和换行标签分别是,HTML 基本标签
  12. 通过PreparedStatement执行更新查询操作
  13. Python 玩转数据 3 - NumPy ndarray Array Indexing, Slicing, Striding, View Subarray,Copy Subarray
  14. 酷派5890详细获取ROOT、以及刷机教程
  15. 计算机启动项在什么地方找,如何查看电脑开机启动项_系统开机启动项快捷键 - 学无忧...
  16. 桌面虚拟化技术介绍和对比
  17. TCP close-wait 状态分析
  18. Cocos Creator 3.0 教程! 标志板! Billboard !
  19. atlas mysql 安装_Atlas安装配置
  20. 数风流人物还看今朝|前后端分离微服务项目常用中间件以及指令

热门文章

  1. 【杂文】Do A Slash
  2. 【PM模块】维护业务处理流程—内部维护(通知单)
  3. SD销售订单输入成本中心
  4. SAP以创新提升极限帆船赛
  5. SAP 大中华区第一季度业绩再创历史新高
  6. SAP 财务会计结构
  7. SAP 供应商寄售业务的标准流程
  8. SAP内向交货详解 Details on SAP inbound delivery
  9. ABAP取字符串中的连续数字
  10. ABAP OO小例子