cv3.io.imread

cv3.io.imread(img_path, flag=1)[source]

Read an image from a file.

Parameters:
  • img_path (str or Path) – Path to the image file.

  • flag (int or str, optional) – Flag specifying the color type of the loaded image. Can be one of: ‘color’, ‘gray’, ‘alpha’, ‘unchanged’ or OpenCV flags. Defaults to cv2.IMREAD_COLOR.

Returns:

Loaded image.

Return type:

numpy.ndarray

Raises:
  • IsADirectoryError – If img_path is a directory.

  • FileNotFoundError – If img_path does not exist.

  • OSError – If the image file cannot be read.

Note

This function automatically handles RGB/BGR color space conversion based on the opt.RGB setting. When opt.RGB is True (default), the image is converted from BGR to RGB.

Example

>>> import cv3
>>> # Read a color image
>>> img = cv3.imread('image.jpg')
>>> # Read a grayscale image
>>> img = cv3.imread('image.jpg', 'gray')
>>> # Read an image with alpha channel
>>> img = cv3.imread('image.png', 'unchanged')