zoukankan      html  css  js  c++  java
  • opencv C++图像读取

    int main(){
        cv::Mat img=cv::imread("/home/nan/图片/highdeepth/starry.jpg",cv::IMREAD_REDUCED_COLOR_8);
         // imread( const String& filename, int flags = IMREAD_COLOR );
        if(img.empty()) return -1;
        cv::imshow("BGR",img);
        std::vector<cv::Mat> planes;
        cv::split(img,planes);
        cv::imshow("B",planes[0]);
        cv::imshow("G",planes[1]);
        cv::imshow("R",planes[2]);
        cv::imshow("BGR",img);
    
        img=cv::imread("/home/nan/图片/highdeepth/starry.jpg",cv::IMREAD_REDUCED_GRAYSCALE_8);
        cv::split(img,planes);  // 灰度图只能分离出一个通道
        cv::imshow("Gray",planes[0]);
        cv::waitKey(0);
        return 0;
    }

    注意:如果图像像素过大,并且要读出全部图像的话可以使用尺寸缩减 如:cv::IMREAD_REDUCED_COLOR_8。

    flags包括以下内容:

        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.
  • 相关阅读:
    利用模板实现c++智能指针
    movit 相关函数(二)
    moveit相关函数解释
    ros常用函数(1)
    Qtcreator中cin函数无法在application output中进行输入的问题的解决
    c++速成,适合有c基础的朋友(3)
    【重要通知】本博客不再更新,更多教程请访问 makermaker.cc
    BBC micro:bit 学习资源汇总(最近更新2019年1月6日....)
    [20个项目学会BBC micro:bit编程] 20-无线通信
    [20个项目学会BBC micro:bit编程] 19-直流电机控制
  • 原文地址:https://www.cnblogs.com/ligei/p/11496113.html
Copyright © 2011-2022 走看看