001// 002// This file is auto-generated. Please don't modify it! 003// 004package org.opencv.imgcodecs; 005 006import java.util.ArrayList; 007import java.util.List; 008import org.opencv.core.Mat; 009import org.opencv.core.MatOfByte; 010import org.opencv.core.MatOfInt; 011import org.opencv.utils.Converters; 012 013// C++: class Imgcodecs 014 015public class Imgcodecs { 016 017 // C++: enum ImreadModes (cv.ImreadModes) 018 public static final int 019 IMREAD_UNCHANGED = -1, 020 IMREAD_GRAYSCALE = 0, 021 IMREAD_COLOR = 1, 022 IMREAD_ANYDEPTH = 2, 023 IMREAD_ANYCOLOR = 4, 024 IMREAD_LOAD_GDAL = 8, 025 IMREAD_REDUCED_GRAYSCALE_2 = 16, 026 IMREAD_REDUCED_COLOR_2 = 17, 027 IMREAD_REDUCED_GRAYSCALE_4 = 32, 028 IMREAD_REDUCED_COLOR_4 = 33, 029 IMREAD_REDUCED_GRAYSCALE_8 = 64, 030 IMREAD_REDUCED_COLOR_8 = 65, 031 IMREAD_IGNORE_ORIENTATION = 128; 032 033 034 // C++: enum ImwriteEXRCompressionFlags (cv.ImwriteEXRCompressionFlags) 035 public static final int 036 IMWRITE_EXR_COMPRESSION_NO = 0, 037 IMWRITE_EXR_COMPRESSION_RLE = 1, 038 IMWRITE_EXR_COMPRESSION_ZIPS = 2, 039 IMWRITE_EXR_COMPRESSION_ZIP = 3, 040 IMWRITE_EXR_COMPRESSION_PIZ = 4, 041 IMWRITE_EXR_COMPRESSION_PXR24 = 5, 042 IMWRITE_EXR_COMPRESSION_B44 = 6, 043 IMWRITE_EXR_COMPRESSION_B44A = 7, 044 IMWRITE_EXR_COMPRESSION_DWAA = 8, 045 IMWRITE_EXR_COMPRESSION_DWAB = 9; 046 047 048 // C++: enum ImwriteEXRTypeFlags (cv.ImwriteEXRTypeFlags) 049 public static final int 050 IMWRITE_EXR_TYPE_HALF = 1, 051 IMWRITE_EXR_TYPE_FLOAT = 2; 052 053 054 // C++: enum ImwriteFlags (cv.ImwriteFlags) 055 public static final int 056 IMWRITE_JPEG_QUALITY = 1, 057 IMWRITE_JPEG_PROGRESSIVE = 2, 058 IMWRITE_JPEG_OPTIMIZE = 3, 059 IMWRITE_JPEG_RST_INTERVAL = 4, 060 IMWRITE_JPEG_LUMA_QUALITY = 5, 061 IMWRITE_JPEG_CHROMA_QUALITY = 6, 062 IMWRITE_JPEG_SAMPLING_FACTOR = 7, 063 IMWRITE_PNG_COMPRESSION = 16, 064 IMWRITE_PNG_STRATEGY = 17, 065 IMWRITE_PNG_BILEVEL = 18, 066 IMWRITE_PXM_BINARY = 32, 067 IMWRITE_EXR_TYPE = (3 << 4) + 0, 068 IMWRITE_EXR_COMPRESSION = (3 << 4) + 1, 069 IMWRITE_EXR_DWA_COMPRESSION_LEVEL = (3 << 4) + 2, 070 IMWRITE_WEBP_QUALITY = 64, 071 IMWRITE_HDR_COMPRESSION = (5 << 4) + 0, 072 IMWRITE_PAM_TUPLETYPE = 128, 073 IMWRITE_TIFF_RESUNIT = 256, 074 IMWRITE_TIFF_XDPI = 257, 075 IMWRITE_TIFF_YDPI = 258, 076 IMWRITE_TIFF_COMPRESSION = 259, 077 IMWRITE_JPEG2000_COMPRESSION_X1000 = 272, 078 IMWRITE_AVIF_QUALITY = 512, 079 IMWRITE_AVIF_DEPTH = 513, 080 IMWRITE_AVIF_SPEED = 514; 081 082 083 // C++: enum ImwriteHDRCompressionFlags (cv.ImwriteHDRCompressionFlags) 084 public static final int 085 IMWRITE_HDR_COMPRESSION_NONE = 0, 086 IMWRITE_HDR_COMPRESSION_RLE = 1; 087 088 089 // C++: enum ImwriteJPEGSamplingFactorParams (cv.ImwriteJPEGSamplingFactorParams) 090 public static final int 091 IMWRITE_JPEG_SAMPLING_FACTOR_411 = 0x411111, 092 IMWRITE_JPEG_SAMPLING_FACTOR_420 = 0x221111, 093 IMWRITE_JPEG_SAMPLING_FACTOR_422 = 0x211111, 094 IMWRITE_JPEG_SAMPLING_FACTOR_440 = 0x121111, 095 IMWRITE_JPEG_SAMPLING_FACTOR_444 = 0x111111; 096 097 098 // C++: enum ImwritePAMFlags (cv.ImwritePAMFlags) 099 public static final int 100 IMWRITE_PAM_FORMAT_NULL = 0, 101 IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, 102 IMWRITE_PAM_FORMAT_GRAYSCALE = 2, 103 IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, 104 IMWRITE_PAM_FORMAT_RGB = 4, 105 IMWRITE_PAM_FORMAT_RGB_ALPHA = 5; 106 107 108 // C++: enum ImwritePNGFlags (cv.ImwritePNGFlags) 109 public static final int 110 IMWRITE_PNG_STRATEGY_DEFAULT = 0, 111 IMWRITE_PNG_STRATEGY_FILTERED = 1, 112 IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2, 113 IMWRITE_PNG_STRATEGY_RLE = 3, 114 IMWRITE_PNG_STRATEGY_FIXED = 4; 115 116 117 // 118 // C++: Mat cv::imread(String filename, int flags = IMREAD_COLOR) 119 // 120 121 /** 122 * Loads an image from a file. 123 * 124 * imread 125 * 126 * The function imread loads an image from the specified file and returns it. If the image cannot be 127 * read (because of missing file, improper permissions, unsupported or invalid format), the function 128 * returns an empty matrix ( Mat::data==NULL ). 129 * 130 * Currently, the following file formats are supported: 131 * 132 * <ul> 133 * <li> 134 * Windows bitmaps - \*.bmp, \*.dib (always supported) 135 * </li> 136 * <li> 137 * JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section) 138 * </li> 139 * <li> 140 * JPEG 2000 files - \*.jp2 (see the *Note* section) 141 * </li> 142 * <li> 143 * Portable Network Graphics - \*.png (see the *Note* section) 144 * </li> 145 * <li> 146 * WebP - \*.webp (see the *Note* section) 147 * </li> 148 * <li> 149 * AVIF - \*.avif (see the *Note* section) 150 * </li> 151 * <li> 152 * Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) 153 * </li> 154 * <li> 155 * PFM files - \*.pfm (see the *Note* section) 156 * </li> 157 * <li> 158 * Sun rasters - \*.sr, \*.ras (always supported) 159 * </li> 160 * <li> 161 * TIFF files - \*.tiff, \*.tif (see the *Note* section) 162 * </li> 163 * <li> 164 * OpenEXR Image files - \*.exr (see the *Note* section) 165 * </li> 166 * <li> 167 * Radiance HDR - \*.hdr, \*.pic (always supported) 168 * </li> 169 * <li> 170 * Raster and Vector geospatial data supported by GDAL (see the *Note* section) 171 * </li> 172 * </ul> 173 * 174 * <b>Note:</b> 175 * <ul> 176 * <li> 177 * The function determines the type of an image by the content, not by the file extension. 178 * </li> 179 * <li> 180 * In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. 181 * </li> 182 * <li> 183 * When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. 184 * Results may differ to the output of cvtColor() 185 * </li> 186 * <li> 187 * On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, 188 * libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, 189 * and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware 190 * that currently these native image loaders give images with different pixel values because of 191 * the color management embedded into MacOSX. 192 * </li> 193 * <li> 194 * On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for 195 * codecs supplied with an OS image. Install the relevant packages (do not forget the development 196 * files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn 197 * on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. 198 * </li> 199 * <li> 200 * In the case you set *WITH_GDAL* flag to true in CMake and REF: IMREAD_LOAD_GDAL to load the image, 201 * then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting 202 * the following formats: [Raster](http://www.gdal.org/formats_list.html), 203 * [Vector](http://www.gdal.org/ogr_formats.html). 204 * </li> 205 * <li> 206 * If EXIF information is embedded in the image file, the EXIF orientation will be taken into account 207 * and thus the image will be rotated accordingly except if the flags REF: IMREAD_IGNORE_ORIENTATION 208 * or REF: IMREAD_UNCHANGED are passed. 209 * </li> 210 * <li> 211 * Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. 212 * </li> 213 * <li> 214 * By default number of pixels must be less than 2^30. Limit can be set using system 215 * variable OPENCV_IO_MAX_IMAGE_PIXELS 216 * </li> 217 * </ul> 218 * 219 * @param filename Name of file to be loaded. 220 * @param flags Flag that can take values of cv::ImreadModes 221 * @return automatically generated 222 */ 223 public static Mat imread(String filename, int flags) { 224 return new Mat(imread_0(filename, flags)); 225 } 226 227 /** 228 * Loads an image from a file. 229 * 230 * imread 231 * 232 * The function imread loads an image from the specified file and returns it. If the image cannot be 233 * read (because of missing file, improper permissions, unsupported or invalid format), the function 234 * returns an empty matrix ( Mat::data==NULL ). 235 * 236 * Currently, the following file formats are supported: 237 * 238 * <ul> 239 * <li> 240 * Windows bitmaps - \*.bmp, \*.dib (always supported) 241 * </li> 242 * <li> 243 * JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section) 244 * </li> 245 * <li> 246 * JPEG 2000 files - \*.jp2 (see the *Note* section) 247 * </li> 248 * <li> 249 * Portable Network Graphics - \*.png (see the *Note* section) 250 * </li> 251 * <li> 252 * WebP - \*.webp (see the *Note* section) 253 * </li> 254 * <li> 255 * AVIF - \*.avif (see the *Note* section) 256 * </li> 257 * <li> 258 * Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) 259 * </li> 260 * <li> 261 * PFM files - \*.pfm (see the *Note* section) 262 * </li> 263 * <li> 264 * Sun rasters - \*.sr, \*.ras (always supported) 265 * </li> 266 * <li> 267 * TIFF files - \*.tiff, \*.tif (see the *Note* section) 268 * </li> 269 * <li> 270 * OpenEXR Image files - \*.exr (see the *Note* section) 271 * </li> 272 * <li> 273 * Radiance HDR - \*.hdr, \*.pic (always supported) 274 * </li> 275 * <li> 276 * Raster and Vector geospatial data supported by GDAL (see the *Note* section) 277 * </li> 278 * </ul> 279 * 280 * <b>Note:</b> 281 * <ul> 282 * <li> 283 * The function determines the type of an image by the content, not by the file extension. 284 * </li> 285 * <li> 286 * In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. 287 * </li> 288 * <li> 289 * When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. 290 * Results may differ to the output of cvtColor() 291 * </li> 292 * <li> 293 * On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, 294 * libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, 295 * and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware 296 * that currently these native image loaders give images with different pixel values because of 297 * the color management embedded into MacOSX. 298 * </li> 299 * <li> 300 * On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for 301 * codecs supplied with an OS image. Install the relevant packages (do not forget the development 302 * files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn 303 * on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. 304 * </li> 305 * <li> 306 * In the case you set *WITH_GDAL* flag to true in CMake and REF: IMREAD_LOAD_GDAL to load the image, 307 * then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting 308 * the following formats: [Raster](http://www.gdal.org/formats_list.html), 309 * [Vector](http://www.gdal.org/ogr_formats.html). 310 * </li> 311 * <li> 312 * If EXIF information is embedded in the image file, the EXIF orientation will be taken into account 313 * and thus the image will be rotated accordingly except if the flags REF: IMREAD_IGNORE_ORIENTATION 314 * or REF: IMREAD_UNCHANGED are passed. 315 * </li> 316 * <li> 317 * Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. 318 * </li> 319 * <li> 320 * By default number of pixels must be less than 2^30. Limit can be set using system 321 * variable OPENCV_IO_MAX_IMAGE_PIXELS 322 * </li> 323 * </ul> 324 * 325 * @param filename Name of file to be loaded. 326 * @return automatically generated 327 */ 328 public static Mat imread(String filename) { 329 return new Mat(imread_1(filename)); 330 } 331 332 333 // 334 // C++: bool cv::imreadmulti(String filename, vector_Mat& mats, int flags = IMREAD_ANYCOLOR) 335 // 336 337 /** 338 * Loads a multi-page image from a file. 339 * 340 * The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects. 341 * @param filename Name of file to be loaded. 342 * @param mats A vector of Mat objects holding each page. 343 * @param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. 344 * SEE: cv::imread 345 * @return automatically generated 346 */ 347 public static boolean imreadmulti(String filename, List<Mat> mats, int flags) { 348 Mat mats_mat = new Mat(); 349 boolean retVal = imreadmulti_0(filename, mats_mat.nativeObj, flags); 350 Converters.Mat_to_vector_Mat(mats_mat, mats); 351 mats_mat.release(); 352 return retVal; 353 } 354 355 /** 356 * Loads a multi-page image from a file. 357 * 358 * The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects. 359 * @param filename Name of file to be loaded. 360 * @param mats A vector of Mat objects holding each page. 361 * SEE: cv::imread 362 * @return automatically generated 363 */ 364 public static boolean imreadmulti(String filename, List<Mat> mats) { 365 Mat mats_mat = new Mat(); 366 boolean retVal = imreadmulti_1(filename, mats_mat.nativeObj); 367 Converters.Mat_to_vector_Mat(mats_mat, mats); 368 mats_mat.release(); 369 return retVal; 370 } 371 372 373 // 374 // C++: bool cv::imreadmulti(String filename, vector_Mat& mats, int start, int count, int flags = IMREAD_ANYCOLOR) 375 // 376 377 /** 378 * Loads a of images of a multi-page image from a file. 379 * 380 * The function imreadmulti loads a specified range from a multi-page image from the specified file into a vector of Mat objects. 381 * @param filename Name of file to be loaded. 382 * @param mats A vector of Mat objects holding each page. 383 * @param start Start index of the image to load 384 * @param count Count number of images to load 385 * @param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. 386 * SEE: cv::imread 387 * @return automatically generated 388 */ 389 public static boolean imreadmulti(String filename, List<Mat> mats, int start, int count, int flags) { 390 Mat mats_mat = new Mat(); 391 boolean retVal = imreadmulti_2(filename, mats_mat.nativeObj, start, count, flags); 392 Converters.Mat_to_vector_Mat(mats_mat, mats); 393 mats_mat.release(); 394 return retVal; 395 } 396 397 /** 398 * Loads a of images of a multi-page image from a file. 399 * 400 * The function imreadmulti loads a specified range from a multi-page image from the specified file into a vector of Mat objects. 401 * @param filename Name of file to be loaded. 402 * @param mats A vector of Mat objects holding each page. 403 * @param start Start index of the image to load 404 * @param count Count number of images to load 405 * SEE: cv::imread 406 * @return automatically generated 407 */ 408 public static boolean imreadmulti(String filename, List<Mat> mats, int start, int count) { 409 Mat mats_mat = new Mat(); 410 boolean retVal = imreadmulti_3(filename, mats_mat.nativeObj, start, count); 411 Converters.Mat_to_vector_Mat(mats_mat, mats); 412 mats_mat.release(); 413 return retVal; 414 } 415 416 417 // 418 // C++: size_t cv::imcount(String filename, int flags = IMREAD_ANYCOLOR) 419 // 420 421 /** 422 * Returns the number of images inside the give file 423 * 424 * The function imcount will return the number of pages in a multi-page image, or 1 for single-page images 425 * @param filename Name of file to be loaded. 426 * @param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. 427 * @return automatically generated 428 */ 429 public static long imcount(String filename, int flags) { 430 return imcount_0(filename, flags); 431 } 432 433 /** 434 * Returns the number of images inside the give file 435 * 436 * The function imcount will return the number of pages in a multi-page image, or 1 for single-page images 437 * @param filename Name of file to be loaded. 438 * @return automatically generated 439 */ 440 public static long imcount(String filename) { 441 return imcount_1(filename); 442 } 443 444 445 // 446 // C++: bool cv::imwrite(String filename, Mat img, vector_int params = std::vector<int>()) 447 // 448 449 /** 450 * Saves an image to a specified file. 451 * 452 * The function imwrite saves the image to the specified file. The image format is chosen based on the 453 * filename extension (see cv::imread for the list of extensions). In general, only 8-bit unsigned (CV_8U) 454 * single-channel or 3-channel (with 'BGR' channel order) images 455 * can be saved using this function, with these exceptions: 456 * 457 * <ul> 458 * <li> 459 * With OpenEXR encoder, only 32-bit float (CV_32F) images can be saved. 460 * <ul> 461 * <li> 462 * 8-bit unsigned (CV_8U) images are not supported. 463 * </li> 464 * </ul> 465 * <li> 466 * With Radiance HDR encoder, non 64-bit float (CV_64F) images can be saved. 467 * <ul> 468 * <li> 469 * All images will be converted to 32-bit float (CV_32F). 470 * </li> 471 * </ul> 472 * <li> 473 * With JPEG 2000 encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 474 * </li> 475 * <li> 476 * With PAM encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 477 * </li> 478 * <li> 479 * With PNG encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 480 * <ul> 481 * <li> 482 * PNG images with an alpha channel can be saved using this function. To do this, create 483 * 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels 484 * should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). 485 * </li> 486 * </ul> 487 * <li> 488 * With PGM/PPM encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 489 * </li> 490 * <li> 491 * With TIFF encoder, 8-bit unsigned (CV_8U), 16-bit unsigned (CV_16U), 492 * 32-bit float (CV_32F) and 64-bit float (CV_64F) images can be saved. 493 * <ul> 494 * <li> 495 * Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below). 496 * </li> 497 * <li> 498 * 32-bit float 3-channel (CV_32FC3) TIFF images will be saved 499 * using the LogLuv high dynamic range encoding (4 bytes per pixel) 500 * </li> 501 * </ul> 502 * 503 * If the image format is not supported, the image will be converted to 8-bit unsigned (CV_8U) and saved that way. 504 * </li> 505 * </ul> 506 * 507 * If the format, depth or channel order is different, use 508 * Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O 509 * functions to save the image to XML or YAML format. 510 * 511 * The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. 512 * It also demonstrates how to save multiple images in a TIFF file: 513 * INCLUDE: snippets/imgcodecs_imwrite.cpp 514 * @param filename Name of the file. 515 * @param img (Mat or vector of Mat) Image or Images to be saved. 516 * @param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags 517 * @return automatically generated 518 */ 519 public static boolean imwrite(String filename, Mat img, MatOfInt params) { 520 Mat params_mat = params; 521 return imwrite_0(filename, img.nativeObj, params_mat.nativeObj); 522 } 523 524 /** 525 * Saves an image to a specified file. 526 * 527 * The function imwrite saves the image to the specified file. The image format is chosen based on the 528 * filename extension (see cv::imread for the list of extensions). In general, only 8-bit unsigned (CV_8U) 529 * single-channel or 3-channel (with 'BGR' channel order) images 530 * can be saved using this function, with these exceptions: 531 * 532 * <ul> 533 * <li> 534 * With OpenEXR encoder, only 32-bit float (CV_32F) images can be saved. 535 * <ul> 536 * <li> 537 * 8-bit unsigned (CV_8U) images are not supported. 538 * </li> 539 * </ul> 540 * <li> 541 * With Radiance HDR encoder, non 64-bit float (CV_64F) images can be saved. 542 * <ul> 543 * <li> 544 * All images will be converted to 32-bit float (CV_32F). 545 * </li> 546 * </ul> 547 * <li> 548 * With JPEG 2000 encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 549 * </li> 550 * <li> 551 * With PAM encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 552 * </li> 553 * <li> 554 * With PNG encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 555 * <ul> 556 * <li> 557 * PNG images with an alpha channel can be saved using this function. To do this, create 558 * 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels 559 * should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). 560 * </li> 561 * </ul> 562 * <li> 563 * With PGM/PPM encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved. 564 * </li> 565 * <li> 566 * With TIFF encoder, 8-bit unsigned (CV_8U), 16-bit unsigned (CV_16U), 567 * 32-bit float (CV_32F) and 64-bit float (CV_64F) images can be saved. 568 * <ul> 569 * <li> 570 * Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below). 571 * </li> 572 * <li> 573 * 32-bit float 3-channel (CV_32FC3) TIFF images will be saved 574 * using the LogLuv high dynamic range encoding (4 bytes per pixel) 575 * </li> 576 * </ul> 577 * 578 * If the image format is not supported, the image will be converted to 8-bit unsigned (CV_8U) and saved that way. 579 * </li> 580 * </ul> 581 * 582 * If the format, depth or channel order is different, use 583 * Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O 584 * functions to save the image to XML or YAML format. 585 * 586 * The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. 587 * It also demonstrates how to save multiple images in a TIFF file: 588 * INCLUDE: snippets/imgcodecs_imwrite.cpp 589 * @param filename Name of the file. 590 * @param img (Mat or vector of Mat) Image or Images to be saved. 591 * @return automatically generated 592 */ 593 public static boolean imwrite(String filename, Mat img) { 594 return imwrite_1(filename, img.nativeObj); 595 } 596 597 598 // 599 // C++: bool cv::imwritemulti(String filename, vector_Mat img, vector_int params = std::vector<int>()) 600 // 601 602 public static boolean imwritemulti(String filename, List<Mat> img, MatOfInt params) { 603 Mat img_mat = Converters.vector_Mat_to_Mat(img); 604 Mat params_mat = params; 605 return imwritemulti_0(filename, img_mat.nativeObj, params_mat.nativeObj); 606 } 607 608 public static boolean imwritemulti(String filename, List<Mat> img) { 609 Mat img_mat = Converters.vector_Mat_to_Mat(img); 610 return imwritemulti_1(filename, img_mat.nativeObj); 611 } 612 613 614 // 615 // C++: Mat cv::imdecode(Mat buf, int flags) 616 // 617 618 /** 619 * Reads an image from a buffer in memory. 620 * 621 * The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or 622 * contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). 623 * 624 * See cv::imread for the list of supported formats and flags description. 625 * 626 * <b>Note:</b> In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. 627 * @param buf Input array or vector of bytes. 628 * @param flags The same flags as in cv::imread, see cv::ImreadModes. 629 * @return automatically generated 630 */ 631 public static Mat imdecode(Mat buf, int flags) { 632 return new Mat(imdecode_0(buf.nativeObj, flags)); 633 } 634 635 636 // 637 // C++: bool cv::imdecodemulti(Mat buf, int flags, vector_Mat& mats) 638 // 639 640 /** 641 * Reads a multi-page image from a buffer in memory. 642 * 643 * The function imdecodemulti reads a multi-page image from the specified buffer in the memory. If the buffer is too short or 644 * contains invalid data, the function returns false. 645 * 646 * See cv::imreadmulti for the list of supported formats and flags description. 647 * 648 * <b>Note:</b> In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. 649 * @param buf Input array or vector of bytes. 650 * @param flags The same flags as in cv::imread, see cv::ImreadModes. 651 * @param mats A vector of Mat objects holding each page, if more than one. 652 * @return automatically generated 653 */ 654 public static boolean imdecodemulti(Mat buf, int flags, List<Mat> mats) { 655 Mat mats_mat = new Mat(); 656 boolean retVal = imdecodemulti_0(buf.nativeObj, flags, mats_mat.nativeObj); 657 Converters.Mat_to_vector_Mat(mats_mat, mats); 658 mats_mat.release(); 659 return retVal; 660 } 661 662 663 // 664 // C++: bool cv::imencode(String ext, Mat img, vector_uchar& buf, vector_int params = std::vector<int>()) 665 // 666 667 /** 668 * Encodes an image into a memory buffer. 669 * 670 * The function imencode compresses the image and stores it in the memory buffer that is resized to fit the 671 * result. See cv::imwrite for the list of supported formats and flags description. 672 * 673 * @param ext File extension that defines the output format. Must include a leading period. 674 * @param img Image to be written. 675 * @param buf Output buffer resized to fit the compressed image. 676 * @param params Format-specific parameters. See cv::imwrite and cv::ImwriteFlags. 677 * @return automatically generated 678 */ 679 public static boolean imencode(String ext, Mat img, MatOfByte buf, MatOfInt params) { 680 Mat buf_mat = buf; 681 Mat params_mat = params; 682 return imencode_0(ext, img.nativeObj, buf_mat.nativeObj, params_mat.nativeObj); 683 } 684 685 /** 686 * Encodes an image into a memory buffer. 687 * 688 * The function imencode compresses the image and stores it in the memory buffer that is resized to fit the 689 * result. See cv::imwrite for the list of supported formats and flags description. 690 * 691 * @param ext File extension that defines the output format. Must include a leading period. 692 * @param img Image to be written. 693 * @param buf Output buffer resized to fit the compressed image. 694 * @return automatically generated 695 */ 696 public static boolean imencode(String ext, Mat img, MatOfByte buf) { 697 Mat buf_mat = buf; 698 return imencode_1(ext, img.nativeObj, buf_mat.nativeObj); 699 } 700 701 702 // 703 // C++: bool cv::haveImageReader(String filename) 704 // 705 706 /** 707 * Returns true if the specified image can be decoded by OpenCV 708 * 709 * @param filename File name of the image 710 * @return automatically generated 711 */ 712 public static boolean haveImageReader(String filename) { 713 return haveImageReader_0(filename); 714 } 715 716 717 // 718 // C++: bool cv::haveImageWriter(String filename) 719 // 720 721 /** 722 * Returns true if an image with the specified filename can be encoded by OpenCV 723 * 724 * @param filename File name of the image 725 * @return automatically generated 726 */ 727 public static boolean haveImageWriter(String filename) { 728 return haveImageWriter_0(filename); 729 } 730 731 732 733 734 // C++: Mat cv::imread(String filename, int flags = IMREAD_COLOR) 735 private static native long imread_0(String filename, int flags); 736 private static native long imread_1(String filename); 737 738 // C++: bool cv::imreadmulti(String filename, vector_Mat& mats, int flags = IMREAD_ANYCOLOR) 739 private static native boolean imreadmulti_0(String filename, long mats_mat_nativeObj, int flags); 740 private static native boolean imreadmulti_1(String filename, long mats_mat_nativeObj); 741 742 // C++: bool cv::imreadmulti(String filename, vector_Mat& mats, int start, int count, int flags = IMREAD_ANYCOLOR) 743 private static native boolean imreadmulti_2(String filename, long mats_mat_nativeObj, int start, int count, int flags); 744 private static native boolean imreadmulti_3(String filename, long mats_mat_nativeObj, int start, int count); 745 746 // C++: size_t cv::imcount(String filename, int flags = IMREAD_ANYCOLOR) 747 private static native long imcount_0(String filename, int flags); 748 private static native long imcount_1(String filename); 749 750 // C++: bool cv::imwrite(String filename, Mat img, vector_int params = std::vector<int>()) 751 private static native boolean imwrite_0(String filename, long img_nativeObj, long params_mat_nativeObj); 752 private static native boolean imwrite_1(String filename, long img_nativeObj); 753 754 // C++: bool cv::imwritemulti(String filename, vector_Mat img, vector_int params = std::vector<int>()) 755 private static native boolean imwritemulti_0(String filename, long img_mat_nativeObj, long params_mat_nativeObj); 756 private static native boolean imwritemulti_1(String filename, long img_mat_nativeObj); 757 758 // C++: Mat cv::imdecode(Mat buf, int flags) 759 private static native long imdecode_0(long buf_nativeObj, int flags); 760 761 // C++: bool cv::imdecodemulti(Mat buf, int flags, vector_Mat& mats) 762 private static native boolean imdecodemulti_0(long buf_nativeObj, int flags, long mats_mat_nativeObj); 763 764 // C++: bool cv::imencode(String ext, Mat img, vector_uchar& buf, vector_int params = std::vector<int>()) 765 private static native boolean imencode_0(String ext, long img_nativeObj, long buf_mat_nativeObj, long params_mat_nativeObj); 766 private static native boolean imencode_1(String ext, long img_nativeObj, long buf_mat_nativeObj); 767 768 // C++: bool cv::haveImageReader(String filename) 769 private static native boolean haveImageReader_0(String filename); 770 771 // C++: bool cv::haveImageWriter(String filename) 772 private static native boolean haveImageWriter_0(String filename); 773 774}