The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PDL::OpenCV::Imgcodecs - PDL bindings for OpenCV Imgcodecs

SYNOPSIS

 use PDL::OpenCV::Imgcodecs;

FUNCTIONS

imread

  Signature: (int [phys] flags(); [o,phys] res(l3,c3,r3); StringWrapper* filename)

Loads an image from a file. NO BROADCASTING.

 $res = imread($filename); # with defaults
 $res = imread($filename,$flags);

@anchor 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) - PFM files - *.pfm (see the *Note* section) - 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) @note - 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. - Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. - 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

imread ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

imreadmulti

  Signature: (int [phys] flags(); byte [o,phys] res(); StringWrapper* filename; [o] vector_MatWrapper * mats)

Loads a multi-page image from a file.

 ($mats,$res) = imreadmulti($filename); # with defaults
 ($mats,$res) = imreadmulti($filename,$flags);

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 also: cv::imread

imreadmulti ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

imreadmulti2

  Signature: (int [phys] start(); int [phys] count(); int [phys] flags(); byte [o,phys] res(); StringWrapper* filename; [o] vector_MatWrapper * mats)

Loads a of images of a multi-page image from a file.

 ($mats,$res) = imreadmulti2($filename,$start,$count); # with defaults
 ($mats,$res) = imreadmulti2($filename,$start,$count,$flags);

The function imreadmulti loads a specified range from a multi-page image from the specified file into a vector of Mat objects.

Parameters:

filename

Name of file to be loaded.

start

Start index of the image to load

count

Count number of images to load

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 also: cv::imread

imreadmulti2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

imcount

Returns the number of images inside the give file

 $res = imcount($filename); # with defaults
 $res = imcount($filename,$flags);

The function imcount will return the number of pages in a multi-page image, or 1 for single-page images

Parameters:

filename

Name of file to be loaded.

flags

Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR.

imwrite

  Signature: ([phys] img(l2,c2,r2); int [phys] params(n3d0); byte [o,phys] res(); StringWrapper* filename)

Saves an image to a specified file.

 $res = imwrite($filename,$img); # with defaults
 $res = imwrite($filename,$img,$params);

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 PFM, 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). If the image format is not supported, the image will be converted to 8-bit unsigned (CV_8U) and saved that way. If the format, depth or channel order is different, use Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O functions to save the image to XML or YAML format. The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. It also demonstrates how to save multiple images in a TIFF file: @include snippets/imgcodecs_imwrite.cpp

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

imwrite ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

imwritemulti

  Signature: (int [phys] params(n3d0); byte [o,phys] res(); StringWrapper* filename; vector_MatWrapper * img)
 $res = imwritemulti($filename,$img); # with defaults
 $res = imwritemulti($filename,$img,$params);

imwritemulti ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

imdecode

  Signature: ([phys] buf(l1,c1,r1); int [phys] flags(); [o,phys] res(l3,c3,r3))

Reads an image from a buffer in memory. NO BROADCASTING.

 $res = imdecode($buf,$flags);

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.

imdecode ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

imencode

  Signature: ([phys] img(l2,c2,r2); byte [o,phys] buf(n3d0); int [phys] params(n4d0); byte [o,phys] res(); StringWrapper* ext)

Encodes an image into a memory buffer. NO BROADCASTING.

 ($buf,$res) = imencode($ext,$img); # with defaults
 ($buf,$res) = imencode($ext,$img,$params);

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.

imencode ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

haveImageReader

Returns true if the specified image can be decoded by OpenCV

 $res = haveImageReader($filename);

Parameters:

filename

File name of the image

haveImageWriter

Returns true if an image with the specified filename can be encoded by OpenCV

 $res = haveImageWriter($filename);

Parameters:

filename

File name of the image

CONSTANTS

PDL::OpenCV::Imgcodecs::IMREAD_UNCHANGED()
PDL::OpenCV::Imgcodecs::IMREAD_GRAYSCALE()
PDL::OpenCV::Imgcodecs::IMREAD_COLOR()
PDL::OpenCV::Imgcodecs::IMREAD_ANYDEPTH()
PDL::OpenCV::Imgcodecs::IMREAD_ANYCOLOR()
PDL::OpenCV::Imgcodecs::IMREAD_LOAD_GDAL()
PDL::OpenCV::Imgcodecs::IMREAD_REDUCED_GRAYSCALE_2()
PDL::OpenCV::Imgcodecs::IMREAD_REDUCED_COLOR_2()
PDL::OpenCV::Imgcodecs::IMREAD_REDUCED_GRAYSCALE_4()
PDL::OpenCV::Imgcodecs::IMREAD_REDUCED_COLOR_4()
PDL::OpenCV::Imgcodecs::IMREAD_REDUCED_GRAYSCALE_8()
PDL::OpenCV::Imgcodecs::IMREAD_REDUCED_COLOR_8()
PDL::OpenCV::Imgcodecs::IMREAD_IGNORE_ORIENTATION()
PDL::OpenCV::Imgcodecs::IMWRITE_JPEG_QUALITY()
PDL::OpenCV::Imgcodecs::IMWRITE_JPEG_PROGRESSIVE()
PDL::OpenCV::Imgcodecs::IMWRITE_JPEG_OPTIMIZE()
PDL::OpenCV::Imgcodecs::IMWRITE_JPEG_RST_INTERVAL()
PDL::OpenCV::Imgcodecs::IMWRITE_JPEG_LUMA_QUALITY()
PDL::OpenCV::Imgcodecs::IMWRITE_JPEG_CHROMA_QUALITY()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_COMPRESSION()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_STRATEGY()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_BILEVEL()
PDL::OpenCV::Imgcodecs::IMWRITE_PXM_BINARY()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_TYPE()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION()
PDL::OpenCV::Imgcodecs::IMWRITE_WEBP_QUALITY()
PDL::OpenCV::Imgcodecs::IMWRITE_PAM_TUPLETYPE()
PDL::OpenCV::Imgcodecs::IMWRITE_TIFF_RESUNIT()
PDL::OpenCV::Imgcodecs::IMWRITE_TIFF_XDPI()
PDL::OpenCV::Imgcodecs::IMWRITE_TIFF_YDPI()
PDL::OpenCV::Imgcodecs::IMWRITE_TIFF_COMPRESSION()
PDL::OpenCV::Imgcodecs::IMWRITE_JPEG2000_COMPRESSION_X1000()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_TYPE_HALF()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_TYPE_FLOAT()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_NO()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_RLE()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_ZIPS()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_ZIP()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_PIZ()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_PXR24()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_B44()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_B44A()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_DWAA()
PDL::OpenCV::Imgcodecs::IMWRITE_EXR_COMPRESSION_DWAB()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_STRATEGY_DEFAULT()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_STRATEGY_FILTERED()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_STRATEGY_RLE()
PDL::OpenCV::Imgcodecs::IMWRITE_PNG_STRATEGY_FIXED()
PDL::OpenCV::Imgcodecs::IMWRITE_PAM_FORMAT_NULL()
PDL::OpenCV::Imgcodecs::IMWRITE_PAM_FORMAT_BLACKANDWHITE()
PDL::OpenCV::Imgcodecs::IMWRITE_PAM_FORMAT_GRAYSCALE()
PDL::OpenCV::Imgcodecs::IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA()
PDL::OpenCV::Imgcodecs::IMWRITE_PAM_FORMAT_RGB()
PDL::OpenCV::Imgcodecs::IMWRITE_PAM_FORMAT_RGB_ALPHA()