opencv4.5.1自学(1)——图像输入输出

1、命名空间

opencv的命名空间为cv,using namespace cv;

2、Mat类型

opencv中的Mat类用于保存图像以及其他矩阵数据。
比如输入一张图片,就用以下代码

Mat myMat = imread("myimage.jpg");

3、图像载入和显示

图像载入函数:

CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );

第一个参数为图片路径名,第二个参数取值如下

enum ImreadModes {
       IMREAD_UNCHANGED            = -1, //Ignore EXIF orientation.
       IMREAD_GRAYSCALE            = 0,  //the single channel grayscale image
       IMREAD_COLOR                = 1,  //the 3 channel BGR color image.
       IMREAD_ANYDEPTH             = 2,  //the corresponding depth, otherwise convert it to 8-bit.
       IMREAD_ANYCOLOR             = 4,  //any possible color format.
       IMREAD_LOAD_GDAL            = 8,  //use the gdal driver for loading the image.
       IMREAD_REDUCED_GRAYSCALE_2  = 16, //always convert image to the single channel grayscale image and the image size reduced 1/2.
       IMREAD_REDUCED_COLOR_2      = 17, //always convert image to the 3 channel BGR color image and the image size reduced 1/2.
       IMREAD_REDUCED_GRAYSCALE_4  = 32, //always convert image to the single channel grayscale image and the image size reduced 1/4.
       IMREAD_REDUCED_COLOR_4      = 33, //always convert image to the 3 channel BGR color image and the image size reduced 1/4.
       IMREAD_REDUCED_GRAYSCALE_8  = 64, //always convert image to the single channel grayscale image and the image size reduced 1/8.
       IMREAD_REDUCED_COLOR_8      = 65, //always convert image to the 3 channel BGR color image and the image size reduced 1/8.
       IMREAD_IGNORE_ORIENTATION   = 128 //do not rotate the image according to EXIF's orientation flag.
     };

创建窗口

CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);

第一个参数为窗口名称,第二个参数取值如下

enum WindowFlags {
       WINDOW_NORMAL     = 0x00000000, //!< the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size.
       WINDOW_AUTOSIZE   = 0x00000001, //!< the user cannot resize the window, the size is constrainted by the image displayed.
       WINDOW_OPENGL     = 0x00001000, //!< window with opengl support.

       WINDOW_FULLSCREEN = 1,          //!< change the window to fullscreen.
       WINDOW_FREERATIO  = 0x00000100, //!< the image expends as much as it can (no ratio constraint).
       WINDOW_KEEPRATIO  = 0x00000000, //!< the ratio of the image is respected.
       WINDOW_GUI_EXPANDED=0x00000000, //!< status bar and tool bar
       WINDOW_GUI_NORMAL = 0x00000010, //!< old fashious way
    };

图像显示函数:

CV_EXPORTS_W void imshow(const String& winname, InputArray mat);

第一个参数为窗口名称,第二个参数为要显示的图像

4、图像输出——imwrite

CV_EXPORTS_W bool imwrite( const String& filename, InputArray img,const std::vector<int>& params = std::vector<int>());

第一个参数为文件名,第二个参数为Mat类型图像数据,第三个参数表示为特定格式保存的参数编码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值