Package org.opencv.imgcodecs
Class Imgcodecs
- java.lang.Object
-
- org.opencv.imgcodecs.Imgcodecs
-
public class Imgcodecs extends java.lang.Object
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Imgcodecs()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Mat
imdecode(Mat buf, int flags)
Reads an image from a buffer in memory.static boolean
imencode(java.lang.String ext, Mat img, MatOfByte buf)
Encodes an image into a memory buffer.static boolean
imencode(java.lang.String ext, Mat img, MatOfByte buf, MatOfInt params)
Encodes an image into a memory buffer.static Mat
imread(java.lang.String filename)
Loads an image from a file.static Mat
imread(java.lang.String filename, int flags)
Loads an image from a file.static boolean
imreadmulti(java.lang.String filename, java.util.List<Mat> mats)
Loads a multi-page image from a file.static boolean
imreadmulti(java.lang.String filename, java.util.List<Mat> mats, int flags)
Loads a multi-page image from a file.static boolean
imwrite(java.lang.String filename, Mat img)
Saves an image to a specified file.static boolean
imwrite(java.lang.String filename, Mat img, MatOfInt params)
Saves an image to a specified file.static boolean
imwritemulti(java.lang.String filename, java.util.List<Mat> img)
static boolean
imwritemulti(java.lang.String filename, java.util.List<Mat> img, MatOfInt params)
-
-
-
Field Detail
-
CV_LOAD_IMAGE_UNCHANGED
public static final int CV_LOAD_IMAGE_UNCHANGED
- See Also:
- Constant Field Values
-
CV_LOAD_IMAGE_GRAYSCALE
public static final int CV_LOAD_IMAGE_GRAYSCALE
- See Also:
- Constant Field Values
-
CV_LOAD_IMAGE_COLOR
public static final int CV_LOAD_IMAGE_COLOR
- See Also:
- Constant Field Values
-
CV_LOAD_IMAGE_ANYDEPTH
public static final int CV_LOAD_IMAGE_ANYDEPTH
- See Also:
- Constant Field Values
-
CV_LOAD_IMAGE_ANYCOLOR
public static final int CV_LOAD_IMAGE_ANYCOLOR
- See Also:
- Constant Field Values
-
CV_LOAD_IMAGE_IGNORE_ORIENTATION
public static final int CV_LOAD_IMAGE_IGNORE_ORIENTATION
- See Also:
- Constant Field Values
-
CV_IMWRITE_JPEG_QUALITY
public static final int CV_IMWRITE_JPEG_QUALITY
- See Also:
- Constant Field Values
-
CV_IMWRITE_JPEG_PROGRESSIVE
public static final int CV_IMWRITE_JPEG_PROGRESSIVE
- See Also:
- Constant Field Values
-
CV_IMWRITE_JPEG_OPTIMIZE
public static final int CV_IMWRITE_JPEG_OPTIMIZE
- See Also:
- Constant Field Values
-
CV_IMWRITE_JPEG_RST_INTERVAL
public static final int CV_IMWRITE_JPEG_RST_INTERVAL
- See Also:
- Constant Field Values
-
CV_IMWRITE_JPEG_LUMA_QUALITY
public static final int CV_IMWRITE_JPEG_LUMA_QUALITY
- See Also:
- Constant Field Values
-
CV_IMWRITE_JPEG_CHROMA_QUALITY
public static final int CV_IMWRITE_JPEG_CHROMA_QUALITY
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_COMPRESSION
public static final int CV_IMWRITE_PNG_COMPRESSION
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_STRATEGY
public static final int CV_IMWRITE_PNG_STRATEGY
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_BILEVEL
public static final int CV_IMWRITE_PNG_BILEVEL
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_STRATEGY_DEFAULT
public static final int CV_IMWRITE_PNG_STRATEGY_DEFAULT
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_STRATEGY_FILTERED
public static final int CV_IMWRITE_PNG_STRATEGY_FILTERED
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY
public static final int CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_STRATEGY_RLE
public static final int CV_IMWRITE_PNG_STRATEGY_RLE
- See Also:
- Constant Field Values
-
CV_IMWRITE_PNG_STRATEGY_FIXED
public static final int CV_IMWRITE_PNG_STRATEGY_FIXED
- See Also:
- Constant Field Values
-
CV_IMWRITE_PXM_BINARY
public static final int CV_IMWRITE_PXM_BINARY
- See Also:
- Constant Field Values
-
CV_IMWRITE_EXR_TYPE
public static final int CV_IMWRITE_EXR_TYPE
- See Also:
- Constant Field Values
-
CV_IMWRITE_WEBP_QUALITY
public static final int CV_IMWRITE_WEBP_QUALITY
- See Also:
- Constant Field Values
-
CV_IMWRITE_PAM_TUPLETYPE
public static final int CV_IMWRITE_PAM_TUPLETYPE
- See Also:
- Constant Field Values
-
CV_IMWRITE_PAM_FORMAT_NULL
public static final int CV_IMWRITE_PAM_FORMAT_NULL
- See Also:
- Constant Field Values
-
CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE
public static final int CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE
- See Also:
- Constant Field Values
-
CV_IMWRITE_PAM_FORMAT_GRAYSCALE
public static final int CV_IMWRITE_PAM_FORMAT_GRAYSCALE
- See Also:
- Constant Field Values
-
CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA
public static final int CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA
- See Also:
- Constant Field Values
-
CV_IMWRITE_PAM_FORMAT_RGB
public static final int CV_IMWRITE_PAM_FORMAT_RGB
- See Also:
- Constant Field Values
-
CV_IMWRITE_PAM_FORMAT_RGB_ALPHA
public static final int CV_IMWRITE_PAM_FORMAT_RGB_ALPHA
- See Also:
- Constant Field Values
-
CV_CVTIMG_FLIP
public static final int CV_CVTIMG_FLIP
- See Also:
- Constant Field Values
-
CV_CVTIMG_SWAP_RB
public static final int CV_CVTIMG_SWAP_RB
- See Also:
- Constant Field Values
-
IMREAD_UNCHANGED
public static final int IMREAD_UNCHANGED
- See Also:
- Constant Field Values
-
IMREAD_GRAYSCALE
public static final int IMREAD_GRAYSCALE
- See Also:
- Constant Field Values
-
IMREAD_COLOR
public static final int IMREAD_COLOR
- See Also:
- Constant Field Values
-
IMREAD_ANYDEPTH
public static final int IMREAD_ANYDEPTH
- See Also:
- Constant Field Values
-
IMREAD_ANYCOLOR
public static final int IMREAD_ANYCOLOR
- See Also:
- Constant Field Values
-
IMREAD_LOAD_GDAL
public static final int IMREAD_LOAD_GDAL
- See Also:
- Constant Field Values
-
IMREAD_REDUCED_GRAYSCALE_2
public static final int IMREAD_REDUCED_GRAYSCALE_2
- See Also:
- Constant Field Values
-
IMREAD_REDUCED_COLOR_2
public static final int IMREAD_REDUCED_COLOR_2
- See Also:
- Constant Field Values
-
IMREAD_REDUCED_GRAYSCALE_4
public static final int IMREAD_REDUCED_GRAYSCALE_4
- See Also:
- Constant Field Values
-
IMREAD_REDUCED_COLOR_4
public static final int IMREAD_REDUCED_COLOR_4
- See Also:
- Constant Field Values
-
IMREAD_REDUCED_GRAYSCALE_8
public static final int IMREAD_REDUCED_GRAYSCALE_8
- See Also:
- Constant Field Values
-
IMREAD_REDUCED_COLOR_8
public static final int IMREAD_REDUCED_COLOR_8
- See Also:
- Constant Field Values
-
IMREAD_IGNORE_ORIENTATION
public static final int IMREAD_IGNORE_ORIENTATION
- See Also:
- Constant Field Values
-
IMWRITE_EXR_TYPE_HALF
public static final int IMWRITE_EXR_TYPE_HALF
- See Also:
- Constant Field Values
-
IMWRITE_EXR_TYPE_FLOAT
public static final int IMWRITE_EXR_TYPE_FLOAT
- See Also:
- Constant Field Values
-
IMWRITE_JPEG_QUALITY
public static final int IMWRITE_JPEG_QUALITY
- See Also:
- Constant Field Values
-
IMWRITE_JPEG_PROGRESSIVE
public static final int IMWRITE_JPEG_PROGRESSIVE
- See Also:
- Constant Field Values
-
IMWRITE_JPEG_OPTIMIZE
public static final int IMWRITE_JPEG_OPTIMIZE
- See Also:
- Constant Field Values
-
IMWRITE_JPEG_RST_INTERVAL
public static final int IMWRITE_JPEG_RST_INTERVAL
- See Also:
- Constant Field Values
-
IMWRITE_JPEG_LUMA_QUALITY
public static final int IMWRITE_JPEG_LUMA_QUALITY
- See Also:
- Constant Field Values
-
IMWRITE_JPEG_CHROMA_QUALITY
public static final int IMWRITE_JPEG_CHROMA_QUALITY
- See Also:
- Constant Field Values
-
IMWRITE_PNG_COMPRESSION
public static final int IMWRITE_PNG_COMPRESSION
- See Also:
- Constant Field Values
-
IMWRITE_PNG_STRATEGY
public static final int IMWRITE_PNG_STRATEGY
- See Also:
- Constant Field Values
-
IMWRITE_PNG_BILEVEL
public static final int IMWRITE_PNG_BILEVEL
- See Also:
- Constant Field Values
-
IMWRITE_PXM_BINARY
public static final int IMWRITE_PXM_BINARY
- See Also:
- Constant Field Values
-
IMWRITE_EXR_TYPE
public static final int IMWRITE_EXR_TYPE
- See Also:
- Constant Field Values
-
IMWRITE_WEBP_QUALITY
public static final int IMWRITE_WEBP_QUALITY
- See Also:
- Constant Field Values
-
IMWRITE_PAM_TUPLETYPE
public static final int IMWRITE_PAM_TUPLETYPE
- See Also:
- Constant Field Values
-
IMWRITE_TIFF_RESUNIT
public static final int IMWRITE_TIFF_RESUNIT
- See Also:
- Constant Field Values
-
IMWRITE_TIFF_XDPI
public static final int IMWRITE_TIFF_XDPI
- See Also:
- Constant Field Values
-
IMWRITE_TIFF_YDPI
public static final int IMWRITE_TIFF_YDPI
- See Also:
- Constant Field Values
-
IMWRITE_TIFF_COMPRESSION
public static final int IMWRITE_TIFF_COMPRESSION
- See Also:
- Constant Field Values
-
IMWRITE_PAM_FORMAT_NULL
public static final int IMWRITE_PAM_FORMAT_NULL
- See Also:
- Constant Field Values
-
IMWRITE_PAM_FORMAT_BLACKANDWHITE
public static final int IMWRITE_PAM_FORMAT_BLACKANDWHITE
- See Also:
- Constant Field Values
-
IMWRITE_PAM_FORMAT_GRAYSCALE
public static final int IMWRITE_PAM_FORMAT_GRAYSCALE
- See Also:
- Constant Field Values
-
IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA
public static final int IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA
- See Also:
- Constant Field Values
-
IMWRITE_PAM_FORMAT_RGB
public static final int IMWRITE_PAM_FORMAT_RGB
- See Also:
- Constant Field Values
-
IMWRITE_PAM_FORMAT_RGB_ALPHA
public static final int IMWRITE_PAM_FORMAT_RGB_ALPHA
- See Also:
- Constant Field Values
-
IMWRITE_PNG_STRATEGY_DEFAULT
public static final int IMWRITE_PNG_STRATEGY_DEFAULT
- See Also:
- Constant Field Values
-
IMWRITE_PNG_STRATEGY_FILTERED
public static final int IMWRITE_PNG_STRATEGY_FILTERED
- See Also:
- Constant Field Values
-
IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY
public static final int IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY
- See Also:
- Constant Field Values
-
IMWRITE_PNG_STRATEGY_RLE
public static final int IMWRITE_PNG_STRATEGY_RLE
- See Also:
- Constant Field Values
-
IMWRITE_PNG_STRATEGY_FIXED
public static final int IMWRITE_PNG_STRATEGY_FIXED
- See Also:
- Constant Field Values
-
-
Method Detail
-
imread
public static Mat imread(java.lang.String filename, int flags)
Loads an image from a file. imread The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL ). Currently, the following file formats are supported:- Windows bitmaps - \*.bmp, \*.dib (always supported)
- JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section)
- JPEG 2000 files - \*.jp2 (see the *Note* section)
- Portable Network Graphics - \*.png (see the *Note* section)
- WebP - \*.webp (see the *Note* section)
- Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported)
- Sun rasters - \*.sr, \*.ras (always supported)
- TIFF files - \*.tiff, \*.tif (see the *Note* section)
- OpenEXR Image files - \*.exr (see the *Note* section)
- Radiance HDR - \*.hdr, \*.pic (always supported)
- Raster and Vector geospatial data supported by GDAL (see the *Note* section)
- The function determines the type of an image by the content, not by the file extension.
- In the case of color images, the decoded images will have the channels stored in B G R order.
- When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. Results may differ to the output of cvtColor()
- On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware that currently these native image loaders give images with different pixel values because of the color management embedded into MacOSX.
- On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with an OS image. Install the relevant packages (do not forget the development files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
- In the case you set *WITH_GDAL* flag to true in CMake and REF: IMREAD_LOAD_GDAL to load the image, then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting the following formats: [Raster](http://www.gdal.org/formats_list.html), [Vector](http://www.gdal.org/ogr_formats.html).
- If EXIF information is embedded in the image file, the EXIF orientation will be taken into account and thus the image will be rotated accordingly except if the flags REF: IMREAD_IGNORE_ORIENTATION or REF: IMREAD_UNCHANGED are passed.
- By default number of pixels must be less than 2^30. Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS
- Parameters:
filename
- Name of file to be loaded.flags
- Flag that can take values of cv::ImreadModes- Returns:
- automatically generated
-
imread
public static Mat imread(java.lang.String filename)
Loads an image from a file. imread The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL ). Currently, the following file formats are supported:- Windows bitmaps - \*.bmp, \*.dib (always supported)
- JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section)
- JPEG 2000 files - \*.jp2 (see the *Note* section)
- Portable Network Graphics - \*.png (see the *Note* section)
- WebP - \*.webp (see the *Note* section)
- Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported)
- Sun rasters - \*.sr, \*.ras (always supported)
- TIFF files - \*.tiff, \*.tif (see the *Note* section)
- OpenEXR Image files - \*.exr (see the *Note* section)
- Radiance HDR - \*.hdr, \*.pic (always supported)
- Raster and Vector geospatial data supported by GDAL (see the *Note* section)
- The function determines the type of an image by the content, not by the file extension.
- In the case of color images, the decoded images will have the channels stored in B G R order.
- When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. Results may differ to the output of cvtColor()
- On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware that currently these native image loaders give images with different pixel values because of the color management embedded into MacOSX.
- On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with an OS image. Install the relevant packages (do not forget the development files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
- In the case you set *WITH_GDAL* flag to true in CMake and REF: IMREAD_LOAD_GDAL to load the image, then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting the following formats: [Raster](http://www.gdal.org/formats_list.html), [Vector](http://www.gdal.org/ogr_formats.html).
- If EXIF information is embedded in the image file, the EXIF orientation will be taken into account and thus the image will be rotated accordingly except if the flags REF: IMREAD_IGNORE_ORIENTATION or REF: IMREAD_UNCHANGED are passed.
- By default number of pixels must be less than 2^30. Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS
- Parameters:
filename
- Name of file to be loaded.- Returns:
- automatically generated
-
imreadmulti
public static boolean imreadmulti(java.lang.String filename, java.util.List<Mat> mats, int flags)
Loads a multi-page image from a file. The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects.- Parameters:
filename
- Name of file to be loaded.flags
- Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR.mats
- A vector of Mat objects holding each page, if more than one. SEE: cv::imread- Returns:
- automatically generated
-
imreadmulti
public static boolean imreadmulti(java.lang.String filename, java.util.List<Mat> mats)
Loads a multi-page image from a file. The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects.- Parameters:
filename
- Name of file to be loaded.mats
- A vector of Mat objects holding each page, if more than one. SEE: cv::imread- Returns:
- automatically generated
-
imwrite
public static boolean imwrite(java.lang.String filename, Mat img, MatOfInt params)
Saves an image to a specified file. The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see cv::imread for the list of extensions). In general, only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function, with these exceptions:- 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats
- 32-bit float (CV_32F) images can be saved in TIFF, OpenEXR, and Radiance HDR formats; 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding (4 bytes per pixel)
- PNG images with an alpha channel can be saved using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below).
- Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below).
- Parameters:
filename
- Name of the file.img
- (Mat or vector of Mat) Image or Images to be saved.params
- Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags- Returns:
- automatically generated
-
imwrite
public static boolean imwrite(java.lang.String filename, Mat img)
Saves an image to a specified file. The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see cv::imread for the list of extensions). In general, only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function, with these exceptions:- 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats
- 32-bit float (CV_32F) images can be saved in TIFF, OpenEXR, and Radiance HDR formats; 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding (4 bytes per pixel)
- PNG images with an alpha channel can be saved using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below).
- Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below).
- Parameters:
filename
- Name of the file.img
- (Mat or vector of Mat) Image or Images to be saved.- Returns:
- automatically generated
-
imwritemulti
public static boolean imwritemulti(java.lang.String filename, java.util.List<Mat> img, MatOfInt params)
-
imwritemulti
public static boolean imwritemulti(java.lang.String filename, java.util.List<Mat> img)
-
imdecode
public static Mat imdecode(Mat buf, int flags)
Reads an image from a buffer in memory. The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). See cv::imread for the list of supported formats and flags description. Note: In the case of color images, the decoded images will have the channels stored in B G R order.- Parameters:
buf
- Input array or vector of bytes.flags
- The same flags as in cv::imread, see cv::ImreadModes.- Returns:
- automatically generated
-
imencode
public static boolean imencode(java.lang.String ext, Mat img, MatOfByte buf, MatOfInt params)
Encodes an image into a memory buffer. The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See cv::imwrite for the list of supported formats and flags description.- Parameters:
ext
- File extension that defines the output format.img
- Image to be written.buf
- Output buffer resized to fit the compressed image.params
- Format-specific parameters. See cv::imwrite and cv::ImwriteFlags.- Returns:
- automatically generated
-
imencode
public static boolean imencode(java.lang.String ext, Mat img, MatOfByte buf)
Encodes an image into a memory buffer. The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See cv::imwrite for the list of supported formats and flags description.- Parameters:
ext
- File extension that defines the output format.img
- Image to be written.buf
- Output buffer resized to fit the compressed image.- Returns:
- automatically generated
-
-