Opencv guardar imagen y leer imagen

contenido

Uno, almacenar la imagen

1, almacenar imwrite

2. Formato de codificación

3. Profundidad de bits de la imagen

Segundo, lee la imagen.

1, leer imleer

2, tipo de lectura ImreadModes


Uno, almacenar la imagen

1, almacenar imwrite

imwrite("D:/im2.jpg", image2);

El tercer parámetro está predeterminado.

2. Formato de codificación

jpg es compresión con pérdida, png es compresión sin pérdida, si tiene requisitos altos para las imágenes, es mejor usar png.

3. Profundidad de bits de la imagen

Las imágenes de tipo 32F, después de guardarlas de esta manera, se convertirán en 8U, y después de leerlas, también serán 8U,

Incluso si se convierte a 32F, puede ser diferente de la imagen original.

Segundo, lee la imagen.

1, leer imleer

string path = "D:/im2.jpg";
Mat image = imread(path, IMREAD_UNCHANGED);
if (!image.data) {
	cout << "imread fail\n";
	return;
}

El segundo parámetro es una enumeración de tipo ImreadModes, que indica el número de canales leídos

Devuelve un objeto de tipo Mat.

Los datos del miembro son un puntero a uchar, si la lectura falla, el puntero es nulo

2, tipo de lectura ImreadModes

Código fuente de ImreadModes:

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.
     };

-1 IMREAD_UNCHANGED significa el número de canales según la imagen en sí

0 IMREAD_GRAYSCALE significa imagen en escala de grises, es decir, canal único

1 IMREAD_COLOR significa según 3 canales

Supongo que te gusta

Origin blog.csdn.net/nameofcsdn/article/details/122966084
Recomendado
Clasificación