opencv中的imread函数用法

C++:Mat imread(const string& filename, intflags=1 );

Python:cv2.imread(filename, flags=None)

其中第一个参数是载入图片名字,第二个参数是int类型的flags,为载入标识,它指定一个加载图像的颜色类型。可以看到它自带缺省值1。其中:
flags >0返回一个3通道的彩色图像。
flags =0返回灰度图像。
flags <0返回包含Alpha通道的加载的图像。
你用函数的时候没有设置第二个参数,就会默认值为1。尽管你读入的是灰度图,还是自动转化成三通道图像。可以将第二个参数置为0得到灰度图像

附:cv2.imread()

imread(filename, flags=None)
filename
imread(filename[, flags]) -> retval . @brief Loads an image from a file. . . @anchor imread . . The function imread loads an image from the specified file and returns it. If the image cannot be . read (because of missing file, improper permissions, unsupported or invalid format), the function . returns an empty matrix ( Mat::data==NULL ). . . Currently, the following file formats are supported: . . - Windows bitmaps - *.bmp, *.dib (always supported) . - JPEG files - *.jpeg, *.jpg, *.jpe (see the Note section) . - JPEG 2000 files - *.jp2 (see the Note section) . - Portable Network Graphics - *.png (see the Note section) . - WebP - *.webp (see the Note section) . - Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported) . - PFM files - *.pfm (see the Note section) . - Sun rasters - *.sr, *.ras (always supported) . - TIFF files - .tiff, .tif (see the Note section) . - OpenEXR Image files - .exr (see the Note section) . - Radiance HDR - .hdr, .pic (always supported) . - Raster and Vector geospatial data supported by GDAL (see the Note section) . . @note . - The function determines the type of an image by the content, not by the file extension. . - In the case of color images, the decoded images will have the channels stored in B G R order. . - When using IMREAD_GRAYSCALE, the codec’s internal grayscale conversion will be used, if available. . Results may differ to the output of cvtColor() . - On Microsoft Windows OS and MacOSX, the codecs shipped with an OpenCV image (libjpeg, . libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, . and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware . that currently these native image loaders give images with different pixel values because of . the color management embedded into MacOSX. . - On Linux, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for . codecs supplied with an OS image. Install the relevant packages (do not forget the development . files, for example, “libjpeg-dev”, in Debian and Ubuntu) to get the codec support or turn . on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. . - In the case you set WITH_GDAL flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image, . then the GDAL driver will be used in order to decode the image, supporting . the following formats: Raster, . Vector. . - If EXIF information are embedded in the image file, the EXIF orientation will be taken into account . and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed. . - Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. . - By default number of pixels must be less than 2^30. Limit can be set using system . variable OPENCV_IO_MAX_IMAGE_PIXELS . . @param filename Name of file to be loaded. . @param flags Flag that can take values of cv::ImreadModes

opencv读入灰度图片却显示三通道相关推荐

  1. 将灰度图片转成三通道(RGB)图片(MatLab)

    运行程序报错: RuntimeError: output with shape [1, 224, 224] doesn't match the broadcast shape [3, 224, 224 ...

  2. OpenCV学习笔记--第一个OpenCV程序:图片读写显示

    配置使用OpenCV库 在上节中我们已经生成了可用于VS2015或者QT5 with MinGW开发的OpenCV库,接下来我们写一个简单的程序测试一下. 因为我电脑上装了QT而没有装VS2015,所 ...

  3. python opencv二值化图像_python opencv,读取彩色图像,提取三通道,图像二值化,提取图像的边缘...

    python opencv,读取彩色图像,提取三通道,图像二值化,提取图像的边缘 python opencv 1,读取图像 2,图像变矩阵 3,图像转灰度图像 4,彩色图像是3D数组 5,灰度图像是2 ...

  4. b g opencv读入的图片 r_OpenCV提取显示一张图片(或者视频)的R,G,B颜色分量

    使用OpenCV可以提分别提取显示一张图片(或者视频)的R,G,B颜色分量.效果如下. 原图: R: G: B: 示例代码如下,貌似很久以前网上找的的,逻辑很清晰,就是把R,G,B三个分量分开,然后显 ...

  5. b g opencv读入的图片 r,OpenCV 读取摄像头并显示图像的R、G、B三个通道的直方图...

    1.读取摄像头 2.从一副彩色图像中分离出R.G.B三个通道(cvSplit) 3.  分别对每个通道图像创建直方图,并显示 源码如下: // Camera_Capture_Histogram.cpp ...

  6. 将三张灰度图转换为RGB三通道图片python

    import cv2 import numpy as np from PIL import Image import matplotlib.pyplot as plt #使用cv2读取图片 img = ...

  7. opencv(C++) 视频处理,通过三通道像素值平均 将视频分辨率缩小为原来的一半

    项目要求: 将一个 1920 * 1080 的视频压缩为 960 * 540 的视频,帧率不变.将每个 2 * 2 相邻像素点的像素值求平均,变成一个新的像素点(即 2 * 2 的平均池化). 程序中 ...

  8. 基于OPENCV的动态图片阵列显示程序

    最近一直在做目标检测的项目,C++写程序真的烦,在面对大量图片显示的时候总觉得只用imshow不太好看,所以就做了这么一个可以动态显示图片阵列的程序,可以选择两种输出方式,一种是固定行列数的,一种是设 ...

  9. opencv中在图片上显示文本

    CvFont font; cvInitFont(&font,CV_FONT_VECTOR0,1,1,0,1,8); //在图像中显示文本字符串 cvPutText(image,"HE ...

最新文章

  1. jquery 获取前两个table里的每个tr里面的第二个td
  2. 四大发明之活字印刷——面向对象思想的胜利
  3. 从欧瑞博看一家典型的深圳硬件公司
  4. sql server schema下拉不到存储过程_mysql数据库字符编码总结--数据存储编码
  5. Vue007_ 表单输入绑定
  6. 让程序员设计界面的后果
  7. android开发自定义选择器,创建自定义android选择器
  8. 字段 密码有效期_你知道Linux中用户们的密码藏在哪儿吗?
  9. 计算机组成原理_计算机组成原理amp;认识Python
  10. 什么是网站的统计代码
  11. HTML 命名规范说明
  12. MongoDB的一些基本使用
  13. 国内大厂首次推出Android统一标准--安卓绿色联盟
  14. 泰坦之路手机版怎么登陆服务器未响应,泰坦之旅一直登入不进去怎么办
  15. 在西安电子科技大学读研是一种什么样的体验
  16. 系统架构设计师-软件水平考试(高级)-论文-架构风格
  17. 旗舰版win7系统电脑administrator密码忘记了破解
  18. Locust 压力测试工具学习(一)
  19. 详谈ORB-SLAM2的地图点MapPoint
  20. 全文翻译【Scaled-YOLOv4: Scaling Cross Stage Partial Netw】

热门文章

  1. pdf 格式文件预览
  2. DataBase Tablespace
  3. MySQL多表查询练习2
  4. OpenCV 模板匹配去重
  5. 漏洞复现----42、Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947)
  6. 蓝桥杯参赛总结(Java B组)
  7. Twig模版语言入门
  8. NFS(共享文件)协议和服务
  9. 全面揭秘Windows激活原理
  10. 2022年塑料管材市场规模