imread
import { imread } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Loads an image from a file.
The imread function loads an image from the specified file and returns OpenCV matrix. If the image cannot be
read (because of a missing file, improper permissions, or unsupported/invalid format), the function
returns an empty matrix.
Currently, the following file formats are supported:
- Windows bitmaps - *.bmp, *.dib (always supported)
- GIF files - *.gif (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)
- AVIF - *.avif (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 its 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 from the output of cvtColor().
- On Microsoft Windows* and Mac OS*, the codecs shipped with OpenCV (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On Mac OS, there is also an option to use native Mac OS image readers. However, beware that currently these native image loaders give images with different pixel values because of the color management embedded into Mac OS.
- On Linux*, BSD flavors, and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with the OS. Ensure the relevant packages are installed (including development files, such as "libjpeg-dev" in Debian* and Ubuntu*) to get codec support, or turn on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
- If the WITH_GDAL flag is set to true in CMake and
IMREAD_LOAD_GDALis used to load the image, the GDAL driver will be used to decode the image, supporting Raster and Vector formats. - 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 unless the flags
IMREAD_IGNORE_ORIENTATIONorIMREAD_UNCHANGEDare passed. - Use the IMREAD_UNCHANGED flag to preserve the floating-point values from PFM images.
- By default, the number of pixels must be less than 2^30. This limit can be changed by setting
the environment variable
OPENCV_IO_MAX_IMAGE_PIXELS. Seetutorial_env_reference.
imread(filename: EmbindString, flags: number): Mat;2 available overloads
imread(filename: EmbindString): Mat;imread(filename: EmbindString, flags: number): Mat;filenameName of the file to be loaded.
flagsFlag that can take values of cv::ImreadModes, default with cv::IMREAD_COLOR_BGR.
The Mat result. Release returned native handles with using or delete(), including handles nested in results.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.