the image reading 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]);
    :: imshow CV ( " R & lt " , Planes [ 2 ]); 
    CV :: imshow ( " the BGR " , IMG); 

    IMG = CV :: imread ( " / Home / NaN3 / image /highdeepth/starry.jpg " , CV IMREAD_REDUCED_GRAYSCALE_8 ::); 
    CV :: Split (IMG, Planes);   // grayscale only one channel separated 
    CV :: imshow ( " Gray " , Planes [ 0 ]); 
    CV :: waitKey ( 0 );
     return  0 ; 
}

Note: If the image pixel is too large, and if you want to read all the images can be used such as size reduction: cv :: IMREAD_REDUCED_COLOR_8.

flags include the following:

    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.

 

Guess you like

Origin www.cnblogs.com/ligei/p/11496113.html