当前位置:网站首页>Opencv learning notes - loading and saving images

Opencv learning notes - loading and saving images

2022-06-24 12:05:00 cc_ rong

Catalog

Image loading :imread() function

Image saving :imwrite() function

Code


Image loading :imread() function

Mat imread(const string& filename, int flags = IMREAD_COLOR  )

Parameter one : The name of the image

Parameter two : Read tag , Used to select how to read pictures , The default value is IMREAD_COLOR,flag The setting of the value is related to the color format used to read the picture .

IMREAD_COLOR:        Always read three channel images

IMREAD_GRAYSCALE:  Always read single channel

IMREAD_ANYCOLOR:    The number of channels is determined by the actual number of channels in the file ( No more than 3)

IMREAD_ANYDEPTH:  Allow loading more than 8bit depth

IMREAD_UNCHANGED: ( When reading an image , Keep in image alpha passageway )

Image format types are supported ;

Image saving :imwrite() function

bool imwrite(const string& filename, 
             InputArray image,
             const vector<int>& params = vector<int>())

  Parameter one : Save the given file name , Extension :

                jpg perhaps jpeg、jp2、tif or tiff、png( Recommended )、bmp、ppm、pgm

Parameter two : Stored input image .

Parameter 3 : Data required for writing to a special type of file

Code


//  Read images 
Mat image = imread("1.jpg");
//  Judge whether the reading is successful 
if(image.data == NULL) {
   return ;
}
//  Show 
imshow("readImg", image);

//  Save image 
if(!imwrite("1To2.jpg", image)) {
    return ;
}
原网站

版权声明
本文为[cc_ rong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241000269374.html