OpenCV的颜色空间转换函数:
 
C++: void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0 )
 
参数dstCn原来一直沿用CV_BGR2GRAY, CV_RGB2GRAY, CV_GRAY2BGR, CV_GRAY2RGB等格式,但最新几个版本的OpenCV已改为COLOR_BGR2GRAY类似形式,今天才看源代码imgproc.hpp才发现,但官方文档还没修改,如下图,如果程序中使用较新的版本OpenCV,采用CV_BGR2GRAY可能会一直出错。
 
 
 
新的OpenCV中imgproc.hpp的定义如下:
enum
{
COLOR_BGR2BGRA =,
COLOR_RGB2RGBA =COLOR_BGR2BGRA, COLOR_BGRA2BGR =,
COLOR_RGBA2RGB =COLOR_BGRA2BGR, COLOR_BGR2RGBA =,
COLOR_RGB2BGRA =COLOR_BGR2RGBA, COLOR_RGBA2BGR =,
COLOR_BGRA2RGB =COLOR_RGBA2BGR, COLOR_BGR2RGB =,
COLOR_RGB2BGR =COLOR_BGR2RGB, COLOR_BGRA2RGBA =,
COLOR_RGBA2BGRA =COLOR_BGRA2RGBA, COLOR_BGR2GRAY =,
COLOR_RGB2GRAY =,
COLOR_GRAY2BGR =,
COLOR_GRAY2RGB =COLOR_GRAY2BGR,
COLOR_GRAY2BGRA =,
COLOR_GRAY2RGBA =COLOR_GRAY2BGRA,
COLOR_BGRA2GRAY =,
COLOR_RGBA2GRAY =, COLOR_BGR2BGR565 =,
COLOR_RGB2BGR565 =,
COLOR_BGR5652BGR =,
COLOR_BGR5652RGB =,
COLOR_BGRA2BGR565 =,
COLOR_RGBA2BGR565 =,
COLOR_BGR5652BGRA =,
COLOR_BGR5652RGBA =, COLOR_GRAY2BGR565 =,
COLOR_BGR5652GRAY =, COLOR_BGR2BGR555 =,
COLOR_RGB2BGR555 =,
COLOR_BGR5552BGR =,
COLOR_BGR5552RGB =,
COLOR_BGRA2BGR555 =,
COLOR_RGBA2BGR555 =,
COLOR_BGR5552BGRA =,
COLOR_BGR5552RGBA =, COLOR_GRAY2BGR555 =,
COLOR_BGR5552GRAY =, COLOR_BGR2XYZ =,
COLOR_RGB2XYZ =,
COLOR_XYZ2BGR =,
COLOR_XYZ2RGB =, COLOR_BGR2YCrCb =,
COLOR_RGB2YCrCb =,
COLOR_YCrCb2BGR =,
COLOR_YCrCb2RGB =, COLOR_BGR2HSV =,
COLOR_RGB2HSV =, COLOR_BGR2Lab =,
COLOR_RGB2Lab =, COLOR_BayerBG2BGR =,
COLOR_BayerGB2BGR =,
COLOR_BayerRG2BGR =,
COLOR_BayerGR2BGR =, COLOR_BayerBG2RGB =COLOR_BayerRG2BGR,
COLOR_BayerGB2RGB =COLOR_BayerGR2BGR,
COLOR_BayerRG2RGB =COLOR_BayerBG2BGR,
COLOR_BayerGR2RGB =COLOR_BayerGB2BGR, COLOR_BGR2Luv =,
COLOR_RGB2Luv =,
COLOR_BGR2HLS =,
COLOR_RGB2HLS =, COLOR_HSV2BGR =,
COLOR_HSV2RGB =, COLOR_Lab2BGR =,
COLOR_Lab2RGB =,
COLOR_Luv2BGR =,
COLOR_Luv2RGB =,
COLOR_HLS2BGR =,
COLOR_HLS2RGB =, COLOR_BayerBG2BGR_VNG =,
COLOR_BayerGB2BGR_VNG =,
COLOR_BayerRG2BGR_VNG =,
COLOR_BayerGR2BGR_VNG =, COLOR_BayerBG2RGB_VNG =COLOR_BayerRG2BGR_VNG,
COLOR_BayerGB2RGB_VNG =COLOR_BayerGR2BGR_VNG,
COLOR_BayerRG2RGB_VNG =COLOR_BayerBG2BGR_VNG,
COLOR_BayerGR2RGB_VNG =COLOR_BayerGB2BGR_VNG, COLOR_BGR2HSV_FULL = ,
COLOR_RGB2HSV_FULL = ,
COLOR_BGR2HLS_FULL = ,
COLOR_RGB2HLS_FULL = , COLOR_HSV2BGR_FULL = ,
COLOR_HSV2RGB_FULL = ,
COLOR_HLS2BGR_FULL = ,
COLOR_HLS2RGB_FULL = , COLOR_LBGR2Lab = ,
COLOR_LRGB2Lab = ,
COLOR_LBGR2Luv = ,
COLOR_LRGB2Luv = , COLOR_Lab2LBGR = ,
COLOR_Lab2LRGB = ,
COLOR_Luv2LBGR = ,
COLOR_Luv2LRGB = , COLOR_BGR2YUV = ,
COLOR_RGB2YUV = ,
COLOR_YUV2BGR = ,
COLOR_YUV2RGB = , COLOR_BayerBG2GRAY = ,
COLOR_BayerGB2GRAY = ,
COLOR_BayerRG2GRAY = ,
COLOR_BayerGR2GRAY = , //YUV 4:2:0 formats family
COLOR_YUV2RGB_NV12 = ,
COLOR_YUV2BGR_NV12 = ,
COLOR_YUV2RGB_NV21 = ,
COLOR_YUV2BGR_NV21 = ,
COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21,
COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21, COLOR_YUV2RGBA_NV12 = ,
COLOR_YUV2BGRA_NV12 = ,
COLOR_YUV2RGBA_NV21 = ,
COLOR_YUV2BGRA_NV21 = ,
COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,
COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21, COLOR_YUV2RGB_YV12 = ,
COLOR_YUV2BGR_YV12 = ,
COLOR_YUV2RGB_IYUV = ,
COLOR_YUV2BGR_IYUV = ,
COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV,
COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV,
COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12,
COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12, COLOR_YUV2RGBA_YV12 = ,
COLOR_YUV2BGRA_YV12 = ,
COLOR_YUV2RGBA_IYUV = ,
COLOR_YUV2BGRA_IYUV = ,
COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,
COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,
COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12,
COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12, COLOR_YUV2GRAY_420 = ,
COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,
COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,
COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420, //YUV 4:2:2 formats family
COLOR_YUV2RGB_UYVY = ,
COLOR_YUV2BGR_UYVY = ,
//COLOR_YUV2RGB_VYUY = 109,
//COLOR_YUV2BGR_VYUY = 110,
COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY,
COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY,
COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY,
COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY, COLOR_YUV2RGBA_UYVY = ,
COLOR_YUV2BGRA_UYVY = ,
//COLOR_YUV2RGBA_VYUY = 113,
//COLOR_YUV2BGRA_VYUY = 114,
COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY,
COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY,
COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY,
COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY, COLOR_YUV2RGB_YUY2 = ,
COLOR_YUV2BGR_YUY2 = ,
COLOR_YUV2RGB_YVYU = ,
COLOR_YUV2BGR_YVYU = ,
COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2,
COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2,
COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2,
COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2, COLOR_YUV2RGBA_YUY2 = ,
COLOR_YUV2BGRA_YUY2 = ,
COLOR_YUV2RGBA_YVYU = ,
COLOR_YUV2BGRA_YVYU = ,
COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2,
COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2,
COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2,
COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2, COLOR_YUV2GRAY_UYVY = ,
COLOR_YUV2GRAY_YUY2 = ,
//COLOR_YUV2GRAY_VYUY = COLOR_YUV2GRAY_UYVY,
COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY,
COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY,
COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2,
COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2,
COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2, // alpha premultiplication
COLOR_RGBA2mRGBA = ,
COLOR_mRGBA2RGBA = , COLOR_RGB2YUV_I420 = ,
COLOR_BGR2YUV_I420 = ,
COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420,
COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420, COLOR_RGBA2YUV_I420 = ,
COLOR_BGRA2YUV_I420 = ,
COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420,
COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420,
COLOR_RGB2YUV_YV12 = ,
COLOR_BGR2YUV_YV12 = ,
COLOR_RGBA2YUV_YV12 = ,
COLOR_BGRA2YUV_YV12 = , COLOR_COLORCVT_MAX =
};

OpenCV 颜色空间转换参数CV_BGR2GRAY改变的更多相关文章

  1. 颜色空间转换 cvtColor()[OpenCV 笔记13]

    void cvtColor(InputArray src, OutputArray dst, ) src: 输入图像 dst: 输出图像 code: 颜色空间转换标识符 OpenCV2的CV_前缀宏命 ...

  2. OpenCV 的颜色空间转换

    # coding: utf-8 ''' 第13章主要介绍:颜色空间转换 ''' import cv2 import numpy as np ''' 经常用到的颜色空间转换是: BGR<-> ...

  3. opencv学习笔记——颜色空间转换函数cv::cvtColor详解

    cv::cvtColor()用于将图像从一个颜色空间转换到另一个颜色空间的转换(目前常见的颜色空间均支持),并且在转换的过程中能够保证数据的类型不变,即转换后的图像的数据类型和位深与源图像一致. 具体 ...

  4. OpenCV 学习笔记(10)HSV颜色空间及颜色空间转换(RGB-HSV)

    1.1 颜色空间介绍 RGB 颜色空间是大家最熟悉的颜色空间,即三基色空间,任何一种颜色都可以由该三种 颜色混合而成.然而一般对颜色空间的图像进行有效处理都是在 HSV 空间进行的,HSV(色 调 H ...

  5. OpenCV学习笔记(5)——颜色空间转换

    学习如歌对图像进行颜色空间转换,从BGR到灰度图,或者从BGR到HSV等 创建一个程序用来从一幅图像中获取某个特定颜色的物体 1.转换颜色空间 OpenCV中有超过150种进行颜色空间转化的方法,但是 ...

  6. python数字图像处理(4):图像数据类型及颜色空间转换

    一.图像数据类型及转换 在skimage中,一张图片就是一个简单的numpy数组,数组的数据类型有很多种,相互之间也可以转换.这些数据类型及取值范围如下表所示: Data type Range uin ...

  7. 【OpenCV-Python】-颜色空间转换

    OpenCV官方教程中文版 for Python,原文为段立辉翻译,感谢Linux公社www.linuxidc.com此文档为自学转述,如有侵权请联系本人 使用工具Python3.6使用包cv2,nu ...

  8. Python-OpenCV中图像颜色空间转换

    目录 cv2.cvtColor() 1. RGB to GRAY 2. RGB to CIE XYZ 3. RGB to YCrCb JPEG 4. RGB to HSV 5. RGB to HLS ...

  9. (Ooencv3)颜色空间转换

    (Ooencv3)颜色空间转换 opencv中有多种色彩空间,包括 RGB.HSI.HSL.HSV.HSB.YCrCb.CIE XYZ.CIE Lab8种,使用中经常要遇到色彩空间的转化,以便生成ma ...

随机推荐

  1. __metaclass__ 实现单列模式

    class Singleton(type): """Singleton. @see: http://stackoverflow.com/questions/6760685 ...

  2. [Leetcode] Backtracking回溯法解题思路

    碎碎念: 最近终于开始刷middle的题了,对于我这个小渣渣确实有点难度,经常一两个小时写出一道题来.在开始写的几道题中,发现大神在discuss中用到回溯法(Backtracking)的概率明显增大 ...

  3. ElasticStack系列之十六 & ElasticSearch5.x index/create 和 update 源码分析

    开篇 在ElasticSearch 系列十四中提到的问题即 ElasticStack系列之十四 & ElasticSearch5.x bulk update 中重复 id 性能骤降,继续这个问 ...

  4. python反射,单例模式

    # getattr# hasattr# setattr# delattr class Foo: def __init__(self, name,age): self.name = name self. ...

  5. C#实现执行数据库事务案例

    我是实际项目来拆出来做的案例,场景是比如我们在做电商网站时,在创建订单时的一系列操作,通常在创建订单时我们需要数据表的操作有:订单的表头(主表).订单的详细.清空购物车.甚至是修改优惠劵的状态(在使用 ...

  6. 跨域问题 Uncaught DOMException: Blocked a frame with origin。。。

    第三方系统内嵌 到iframe中的 跨域问题. 解决方案: http://www.ruanyifeng.com/blog/2016/04/same-origin-policy.html

  7. Jenkins git 的配置及问题解决

    背景:最近项目需要 Jenkins 集成git,着手记录遇到的问题及解决方式 一.搭建Jenkins环境步骤这里(略) 二.安装Jenkins插件(系统管理-->插件管理-->可选插件)选 ...

  8. Jdbc druid数据库连接池

    //测试类package druid; import util.JdbcUtilsDruid; import java.sql.Connection; import java.sql.Date; im ...

  9. JavaScript中函数和构造函数的区别

    构造函数也是函数 构造函数和其它函数的唯一区别: 构造函数是通过new操作符来调用的. 也就是说如果构造函数不用new操作符来调用,那它就是普通函数,反过来说任何函数通过new操作符来调用就可以当做构 ...

  10. windows下用python转换markdown到html

    方法一: 安装markdown, pip install markdown, 安装好后,python -m markdown xxx.md -f xxx.html 方法二:安装markdown2, p ...