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_PNG_COMPRESSION = 16, 063 IMWRITE_PNG_STRATEGY = 17, 064 IMWRITE_PNG_BILEVEL = 18, 065 IMWRITE_PXM_BINARY = 32, 066 IMWRITE_EXR_TYPE = (3 << 4) + 0, 067 IMWRITE_EXR_COMPRESSION = (3 << 4) + 1, 068 IMWRITE_WEBP_QUALITY = 64, 069 IMWRITE_PAM_TUPLETYPE = 128, 070 IMWRITE_TIFF_RESUNIT = 256, 071 IMWRITE_TIFF_XDPI = 257, 072 IMWRITE_TIFF_YDPI = 258, 073 IMWRITE_TIFF_COMPRESSION = 259, 074 IMWRITE_JPEG2000_COMPRESSION_X1000 = 272; 075 076 077 // C++: enum ImwritePAMFlags (cv.ImwritePAMFlags) 078 public static final int 079 IMWRITE_PAM_FORMAT_NULL = 0, 080 IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, 081 IMWRITE_PAM_FORMAT_GRAYSCALE = 2, 082 IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, 083 IMWRITE_PAM_FORMAT_RGB = 4, 084 IMWRITE_PAM_FORMAT_RGB_ALPHA = 5; 085 086 087 // C++: enum ImwritePNGFlags (cv.ImwritePNGFlags) 088 public static final int 089 IMWRITE_PNG_STRATEGY_DEFAULT = 0, 090 IMWRITE_PNG_STRATEGY_FILTERED = 1, 091 IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2, 092 IMWRITE_PNG_STRATEGY_RLE = 3, 093 IMWRITE_PNG_STRATEGY_FIXED = 4; 094 095 096 // 097 // C++: Mat cv::imread(String filename, int flags = IMREAD_COLOR) 098 // 099 100 /** 101 * Loads an image from a file. 102 * 103 * imread 104 * 105 * The function imread loads an image from the specified file and returns it. If the image cannot be 106 * read (because of missing file, improper permissions, unsupported or invalid format), the function 107 * returns an empty matrix ( Mat::data==NULL ). 108 * 109 * Currently, the following file formats are supported: 110 * 111 * <ul> 112 * <li> 113 * Windows bitmaps - \*.bmp, \*.dib (always supported) 114 * </li> 115 * <li> 116 * JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section) 117 * </li> 118 * <li> 119 * JPEG 2000 files - \*.jp2 (see the *Note* section) 120 * </li> 121 * <li> 122 * Portable Network Graphics - \*.png (see the *Note* section) 123 * </li> 124 * <li> 125 * WebP - \*.webp (see the *Note* section) 126 * </li> 127 * <li> 128 * Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) 129 * </li> 130 * <li> 131 * PFM files - \*.pfm (see the *Note* section) 132 * </li> 133 * <li> 134 * Sun rasters - \*.sr, \*.ras (always supported) 135 * </li> 136 * <li> 137 * TIFF files - \*.tiff, \*.tif (see the *Note* section) 138 * </li> 139 * <li> 140 * OpenEXR Image files - \*.exr (see the *Note* section) 141 * </li> 142 * <li> 143 * Radiance HDR - \*.hdr, \*.pic (always supported) 144 * </li> 145 * <li> 146 * Raster and Vector geospatial data supported by GDAL (see the *Note* section) 147 * </li> 148 * </ul> 149 * 150 * <b>Note:</b> 151 * <ul> 152 * <li> 153 * The function determines the type of an image by the content, not by the file extension. 154 * </li> 155 * <li> 156 * In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. 157 * </li> 158 * <li> 159 * When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. 160 * Results may differ to the output of cvtColor() 161 * </li> 162 * <li> 163 * On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, 164 * libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, 165 * and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware 166 * that currently these native image loaders give images with different pixel values because of 167 * the color management embedded into MacOSX. 168 * </li> 169 * <li> 170 * On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for 171 * codecs supplied with an OS image. Install the relevant packages (do not forget the development 172 * files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn 173 * on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. 174 * </li> 175 * <li> 176 * In the case you set *WITH_GDAL* flag to true in CMake and REF: IMREAD_LOAD_GDAL to load the image, 177 * then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting 178 * the following formats: [Raster](http://www.gdal.org/formats_list.html), 179 * [Vector](http://www.gdal.org/ogr_formats.html). 180 * </li> 181 * <li> 182 * If EXIF information is embedded in the image file, the EXIF orientation will be taken into account 183 * and thus the image will be rotated accordingly except if the flags REF: IMREAD_IGNORE_ORIENTATION 184 * or REF: IMREAD_UNCHANGED are passed. 185 * </li> 186 * <li> 187 * Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. 188 * </li> 189 * <li> 190 * By default number of pixels must be less than 2^30. Limit can be set using system 191 * variable OPENCV_IO_MAX_IMAGE_PIXELS 192 * </li> 193 * </ul> 194 * 195 * @param filename Name of file to be loaded. 196 * @param flags Flag that can take values of cv::ImreadModes 197 * @return automatically generated 198 */ 199 public static Mat imread(String filename, int flags) { 200 return new Mat(imread_0(filename, flags)); 201 } 202 203 /** 204 * Loads an image from a file. 205 * 206 * imread 207 * 208 * The function imread loads an image from the specified file and returns it. If the image cannot be 209 * read (because of missing file, improper permissions, unsupported or invalid format), the function 210 * returns an empty matrix ( Mat::data==NULL ). 211 * 212 * Currently, the following file formats are supported: 213 * 214 * <ul> 215 * <li> 216 * Windows bitmaps - \*.bmp, \*.dib (always supported) 217 * </li> 218 * <li> 219 * JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section) 220 * </li> 221 * <li> 222 * JPEG 2000 files - \*.jp2 (see the *Note* section) 223 * </li> 224 * <li> 225 * Portable Network Graphics - \*.png (see the *Note* section) 226 * </li> 227 * <li> 228 * WebP - \*.webp (see the *Note* section) 229 * </li> 230 * <li> 231 * Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) 232 * </li> 233 * <li> 234 * PFM files - \*.pfm (see the *Note* section) 235 * </li> 236 * <li> 237 * Sun rasters - \*.sr, \*.ras (always supported) 238 * </li> 239 * <li> 240 * TIFF files - \*.tiff, \*.tif (see the *Note* section) 241 * </li> 242 * <li> 243 * OpenEXR Image files - \*.exr (see the *Note* section) 244 * </li> 245 * <li> 246 * Radiance HDR - \*.hdr, \*.pic (always supported) 247 * </li> 248 * <li> 249 * Raster and Vector geospatial data supported by GDAL (see the *Note* section) 250 * </li> 251 * </ul> 252 * 253 * <b>Note:</b> 254 * <ul> 255 * <li> 256 * The function determines the type of an image by the content, not by the file extension. 257 * </li> 258 * <li> 259 * In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. 260 * </li> 261 * <li> 262 * When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. 263 * Results may differ to the output of cvtColor() 264 * </li> 265 * <li> 266 * On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, 267 * libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, 268 * and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware 269 * that currently these native image loaders give images with different pixel values because of 270 * the color management embedded into MacOSX. 271 * </li> 272 * <li> 273 * On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for 274 * codecs supplied with an OS image. Install the relevant packages (do not forget the development 275 * files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn 276 * on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. 277 * </li> 278 * <li> 279 * In the case you set *WITH_GDAL* flag to true in CMake and REF: IMREAD_LOAD_GDAL to load the image, 280 * then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting 281 * the following formats: [Raster](http://www.gdal.org/formats_list.html), 282 * [Vector](http://www.gdal.org/ogr_formats.html). 283 * </li> 284 * <li> 285 * If EXIF information is embedded in the image file, the EXIF orientation will be taken into account 286 * and thus the image will be rotated accordingly except if the flags REF: IMREAD_IGNORE_ORIENTATION 287 * or REF: IMREAD_UNCHANGED are passed. 288 * </li> 289 * <li> 290 * Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. 291 * </li> 292 * <li> 293 * By default number of pixels must be less than 2^30. Limit can be set using system 294 * variable OPENCV_IO_MAX_IMAGE_PIXELS 295 * </li> 296 * </ul> 297 * 298 * @param filename Name of file to be loaded. 299 * @return automatically generated 300 */ 301 public static Mat imread(String filename) { 302 return new Mat(imread_1(filename)); 303 } 304 305 306 // 307 // C++: bool cv::imreadmulti(String filename, vector_Mat& mats, int flags = IMREAD_ANYCOLOR) 308 // 309 310 /** 311 * Loads a multi-page image from a file. 312 * 313 * The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects. 314 * @param filename Name of file to be loaded. 315 * @param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. 316 * @param mats A vector of Mat objects holding each page, if more than one. 317 * SEE: cv::imread 318 * @return automatically generated 319 */ 320 public static boolean imreadmulti(String filename, List<Mat> mats, int flags) { 321 Mat mats_mat = new Mat(); 322 boolean retVal = imreadmulti_0(filename, mats_mat.nativeObj, flags); 323 Converters.Mat_to_vector_Mat(mats_mat, mats); 324 mats_mat.release(); 325 return retVal; 326 } 327 328 /** 329 * Loads a multi-page image from a file. 330 * 331 * The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects. 332 * @param filename Name of file to be loaded. 333 * @param mats A vector of Mat objects holding each page, if more than one. 334 * SEE: cv::imread 335 * @return automatically generated 336 */ 337 public static boolean imreadmulti(String filename, List<Mat> mats) { 338 Mat mats_mat = new Mat(); 339 boolean retVal = imreadmulti_1(filename, mats_mat.nativeObj); 340 Converters.Mat_to_vector_Mat(mats_mat, mats); 341 mats_mat.release(); 342 return retVal; 343 } 344 345 346 // 347 // C++: bool cv::imwrite(String filename, Mat img, vector_int params = std::vector<int>()) 348 // 349 350 /** 351 * Saves an image to a specified file. 352 * 353 * The function imwrite saves the image to the specified file. The image format is chosen based on the 354 * filename extension (see cv::imread for the list of extensions). In general, only 8-bit 355 * single-channel or 3-channel (with 'BGR' channel order) images 356 * can be saved using this function, with these exceptions: 357 * 358 * <ul> 359 * <li> 360 * 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats 361 * </li> 362 * <li> 363 * 32-bit float (CV_32F) images can be saved in PFM, TIFF, OpenEXR, and Radiance HDR formats; 364 * 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding 365 * (4 bytes per pixel) 366 * </li> 367 * <li> 368 * PNG images with an alpha channel can be saved using this function. To do this, create 369 * 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels 370 * should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). 371 * </li> 372 * <li> 373 * Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below). 374 * </li> 375 * </ul> 376 * 377 * If the format, depth or channel order is different, use 378 * Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O 379 * functions to save the image to XML or YAML format. 380 * 381 * The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. 382 * It also demonstrates how to save multiple images in a TIFF file: 383 * INCLUDE: snippets/imgcodecs_imwrite.cpp 384 * @param filename Name of the file. 385 * @param img (Mat or vector of Mat) Image or Images to be saved. 386 * @param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags 387 * @return automatically generated 388 */ 389 public static boolean imwrite(String filename, Mat img, MatOfInt params) { 390 Mat params_mat = params; 391 return imwrite_0(filename, img.nativeObj, params_mat.nativeObj); 392 } 393 394 /** 395 * Saves an image to a specified file. 396 * 397 * The function imwrite saves the image to the specified file. The image format is chosen based on the 398 * filename extension (see cv::imread for the list of extensions). In general, only 8-bit 399 * single-channel or 3-channel (with 'BGR' channel order) images 400 * can be saved using this function, with these exceptions: 401 * 402 * <ul> 403 * <li> 404 * 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats 405 * </li> 406 * <li> 407 * 32-bit float (CV_32F) images can be saved in PFM, TIFF, OpenEXR, and Radiance HDR formats; 408 * 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding 409 * (4 bytes per pixel) 410 * </li> 411 * <li> 412 * PNG images with an alpha channel can be saved using this function. To do this, create 413 * 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels 414 * should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). 415 * </li> 416 * <li> 417 * Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below). 418 * </li> 419 * </ul> 420 * 421 * If the format, depth or channel order is different, use 422 * Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O 423 * functions to save the image to XML or YAML format. 424 * 425 * The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. 426 * It also demonstrates how to save multiple images in a TIFF file: 427 * INCLUDE: snippets/imgcodecs_imwrite.cpp 428 * @param filename Name of the file. 429 * @param img (Mat or vector of Mat) Image or Images to be saved. 430 * @return automatically generated 431 */ 432 public static boolean imwrite(String filename, Mat img) { 433 return imwrite_1(filename, img.nativeObj); 434 } 435 436 437 // 438 // C++: bool cv::imwritemulti(String filename, vector_Mat img, vector_int params = std::vector<int>()) 439 // 440 441 public static boolean imwritemulti(String filename, List<Mat> img, MatOfInt params) { 442 Mat img_mat = Converters.vector_Mat_to_Mat(img); 443 Mat params_mat = params; 444 return imwritemulti_0(filename, img_mat.nativeObj, params_mat.nativeObj); 445 } 446 447 public static boolean imwritemulti(String filename, List<Mat> img) { 448 Mat img_mat = Converters.vector_Mat_to_Mat(img); 449 return imwritemulti_1(filename, img_mat.nativeObj); 450 } 451 452 453 // 454 // C++: Mat cv::imdecode(Mat buf, int flags) 455 // 456 457 /** 458 * Reads an image from a buffer in memory. 459 * 460 * The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or 461 * contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). 462 * 463 * See cv::imread for the list of supported formats and flags description. 464 * 465 * <b>Note:</b> In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. 466 * @param buf Input array or vector of bytes. 467 * @param flags The same flags as in cv::imread, see cv::ImreadModes. 468 * @return automatically generated 469 */ 470 public static Mat imdecode(Mat buf, int flags) { 471 return new Mat(imdecode_0(buf.nativeObj, flags)); 472 } 473 474 475 // 476 // C++: bool cv::imencode(String ext, Mat img, vector_uchar& buf, vector_int params = std::vector<int>()) 477 // 478 479 /** 480 * Encodes an image into a memory buffer. 481 * 482 * The function imencode compresses the image and stores it in the memory buffer that is resized to fit the 483 * result. See cv::imwrite for the list of supported formats and flags description. 484 * 485 * @param ext File extension that defines the output format. 486 * @param img Image to be written. 487 * @param buf Output buffer resized to fit the compressed image. 488 * @param params Format-specific parameters. See cv::imwrite and cv::ImwriteFlags. 489 * @return automatically generated 490 */ 491 public static boolean imencode(String ext, Mat img, MatOfByte buf, MatOfInt params) { 492 Mat buf_mat = buf; 493 Mat params_mat = params; 494 return imencode_0(ext, img.nativeObj, buf_mat.nativeObj, params_mat.nativeObj); 495 } 496 497 /** 498 * Encodes an image into a memory buffer. 499 * 500 * The function imencode compresses the image and stores it in the memory buffer that is resized to fit the 501 * result. See cv::imwrite for the list of supported formats and flags description. 502 * 503 * @param ext File extension that defines the output format. 504 * @param img Image to be written. 505 * @param buf Output buffer resized to fit the compressed image. 506 * @return automatically generated 507 */ 508 public static boolean imencode(String ext, Mat img, MatOfByte buf) { 509 Mat buf_mat = buf; 510 return imencode_1(ext, img.nativeObj, buf_mat.nativeObj); 511 } 512 513 514 // 515 // C++: bool cv::haveImageReader(String filename) 516 // 517 518 /** 519 * Returns true if the specified image can be decoded by OpenCV 520 * 521 * @param filename File name of the image 522 * @return automatically generated 523 */ 524 public static boolean haveImageReader(String filename) { 525 return haveImageReader_0(filename); 526 } 527 528 529 // 530 // C++: bool cv::haveImageWriter(String filename) 531 // 532 533 /** 534 * Returns true if an image with the specified filename can be encoded by OpenCV 535 * 536 * @param filename File name of the image 537 * @return automatically generated 538 */ 539 public static boolean haveImageWriter(String filename) { 540 return haveImageWriter_0(filename); 541 } 542 543 544 545 546 // C++: Mat cv::imread(String filename, int flags = IMREAD_COLOR) 547 private static native long imread_0(String filename, int flags); 548 private static native long imread_1(String filename); 549 550 // C++: bool cv::imreadmulti(String filename, vector_Mat& mats, int flags = IMREAD_ANYCOLOR) 551 private static native boolean imreadmulti_0(String filename, long mats_mat_nativeObj, int flags); 552 private static native boolean imreadmulti_1(String filename, long mats_mat_nativeObj); 553 554 // C++: bool cv::imwrite(String filename, Mat img, vector_int params = std::vector<int>()) 555 private static native boolean imwrite_0(String filename, long img_nativeObj, long params_mat_nativeObj); 556 private static native boolean imwrite_1(String filename, long img_nativeObj); 557 558 // C++: bool cv::imwritemulti(String filename, vector_Mat img, vector_int params = std::vector<int>()) 559 private static native boolean imwritemulti_0(String filename, long img_mat_nativeObj, long params_mat_nativeObj); 560 private static native boolean imwritemulti_1(String filename, long img_mat_nativeObj); 561 562 // C++: Mat cv::imdecode(Mat buf, int flags) 563 private static native long imdecode_0(long buf_nativeObj, int flags); 564 565 // C++: bool cv::imencode(String ext, Mat img, vector_uchar& buf, vector_int params = std::vector<int>()) 566 private static native boolean imencode_0(String ext, long img_nativeObj, long buf_mat_nativeObj, long params_mat_nativeObj); 567 private static native boolean imencode_1(String ext, long img_nativeObj, long buf_mat_nativeObj); 568 569 // C++: bool cv::haveImageReader(String filename) 570 private static native boolean haveImageReader_0(String filename); 571 572 // C++: bool cv::haveImageWriter(String filename) 573 private static native boolean haveImageWriter_0(String filename); 574 575}