imread 函数 的相关细节

简介:

 第一个参数是图片的名称,如果是固定的,强烈建议使用/作为目录的分割符号

 第二参数具有如下的值,说明了读取过程中是否需要进行像素的操作,例如取值0,表示读取过程中将像素转换为灰度值,默认参数是1, 表示不改变原图像的像素

enum ImreadModes {

       IMREAD_UNCHANGED            = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).

       IMREAD_GRAYSCALE            = 0,  //!< If set, always convert image to the single channel grayscale image.

       IMREAD_COLOR                = 1,  //!< If set, always convert image to the 3 channel BGR color image.

       IMREAD_ANYDEPTH             = 2,  //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.

       IMREAD_ANYCOLOR             = 4,  //!< If set, the image is read in any possible color format.

       IMREAD_LOAD_GDAL            = 8,  //!< If set, use the gdal driver for loading the image.

       IMREAD_REDUCED_GRAYSCALE_2  = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.

       IMREAD_REDUCED_COLOR_2      = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.

       IMREAD_REDUCED_GRAYSCALE_4  = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.

       IMREAD_REDUCED_COLOR_4      = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.

       IMREAD_REDUCED_GRAYSCALE_8  = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.

       IMREAD_REDUCED_COLOR_8      = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.

       IMREAD_IGNORE_ORIENTATION   = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.

     };


注意:

在进行图像的灰度值处理之后,默认情况下, 不会进行图像的直方图进行图像的增强,否则会出现运行异常

代码

#include <opencv2/highgui/highgui.hpp>    

#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>


using namespace cv;


int main(int argc, char *argv[])

{

  Mat image = imread("D:/20170601092226.png", 0);

  if (image.empty())

  {

    std::cout << "打开图片失败,请检查" << std::endl;

    return -1;

  }

  imshow("原图像", image);

  waitKey();

  return 0;

  Mat imageRGB[3];

  split(image, imageRGB);

  for (int i = 0; i < 3; i++)

  {

    equalizeHist(imageRGB[i], imageRGB[i]);

  }

  merge(imageRGB, 3, image);

  imshow("直方图均衡化图像增强效果", image);

  waitKey();

  return 0;

}





    本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1887418,如需转载请自行联系原作者


相关文章
|
2月前
|
监控 API 计算机视觉
OpenCV这么简单为啥不学——1.3、图像缩放resize函数
OpenCV这么简单为啥不学——1.3、图像缩放resize函数
40 0
|
1月前
|
存储 算法 数据可视化
|
2月前
|
监控 API 图形学
OpenCV这么简单为啥不学——1、基础环境与imread函数
OpenCV这么简单为啥不学——1、基础环境与imread函数
30 0
|
4月前
|
计算机视觉
OpenCV中GRAY、HSV色彩空间的简介及与BGR色彩空间的转换演示(附源码 超详细)
OpenCV中GRAY、HSV色彩空间的简介及与BGR色彩空间的转换演示(附源码 超详细)
75 0
|
9月前
|
开发者 Kotlin
将JPG图像根据色彩范围转换为PNG透明图像(kotlin)
这实际上是一个十分普遍的需求,在kotlin中如何完成这一任务呢?其实这样简单的操作不需要任何三方库,只需要BufferedImage的原生功能就能做到,约60行代码
125 0
|
5月前
|
存储 算法 计算机视觉
PIL中ImageFilter模块几种图片滤波处理和使用方法
PIL中ImageFilter模块几种图片滤波处理和使用方法
41 0
|
7月前
|
计算机视觉
13.【openCV_imread()函数详解】
13.【openCV_imread()函数详解】
25 0
|
8月前
|
JSON 数据格式
cv2.fillPoly的大坑
在labelme标注图像后,想将其json文件转化为png的图像,我们这里使用cv2.fillPoly()进行转化,但是遇到了一个巨坑
186 0
|
9月前
|
编解码 计算机视觉
OpenCv-cv2.imshow()显示图片不全
OpenCv-cv2.imshow()显示图片不全
219 0
|
9月前
|
存储 计算机视觉 C++
【OpenCv】c++ 入门认识 Mat 类,单通道 Mat 的基本操作
【OpenCv】c++ 入门认识 Mat 类,单通道 Mat 的基本操作
182 0