solitaryclown

opencv基础操作

2023-06-23
solitaryclown

opencv基础操作

图像读取显示

  1. 读取图像

    Mat imread( const String& filename, int flags = IMREAD_COLOR ):读取图像,返回Mat实例 参数:

    • flags:图像读取模式,
       enum ImreadModes {
       IMREAD_UNCHANGED            = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.
       IMREAD_GRAYSCALE            = 0,  //!< If set, always convert image to the single channel grayscale image (codec internal conversion).
       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.
        };
      
  2. 显示图像

    void imshow(const String& winname, InputArray mat):显示图像

    • winname:窗口标题
    • mat:要显示的图像
  3. 创建窗口

    namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE):创建一个命名窗口

    • winname:窗口标题
    • flags:创建窗口的类型
      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
       };
      
  4. 写入图片到文件

    bool imwrite( const String& filename, InputArray img,const std::vector<int>& params = std::vector<int>()):写入图片到文件

    • filename:图片路径
    • img:要写入的图片
    • params:特定格式的参数
      • jpg: params代表0-100的图像质量(CV_IMWRITE_JPEG_QUALITY),默认值是95
      • png: params代表压缩级别,从0-9(CV_IMWRITE_PNG_COMPRESSION),较高的值代表更小的尺寸和更长的压缩时间,默认值是3

上一篇 opencv-HighGUI

下一篇 opencv-core

Comments

Content