docstr: Read an image from the ImageResource.
  
  Parameters
  ----------
  index : int, Ellipsis
      If int, read the index-th image from the ImageResource. If ``...``,
      read all images from the ImageResource and stack them along a new,
      prepended, batch dimension. If None (default), use ``index=0`` if
      the image contains exactly one image and ``index=...`` otherwise.
  colorspace : str, int
      The colorspace to convert into after loading and before returning
      the image. If None (default) keep grayscale images as is, convert
      images with an alpha channel to ``RGBA`` and all other images to
      ``RGB``. If int, interpret ``colorspace`` as one of OpenCVs
      `conversion flags
      <https://docs.opencv.org/4.x/d8/d01/group__imgproc__color__conversions.html>`_
      and use it for conversion. If str, convert the image into the given
      colorspace. Possible string values are: ``"RGB"``, ``"BGR"``,
      ``"RGBA"``, ``"BGRA"``, ``"GRAY"``, ``"HSV"``, or ``"LAB"``.
  flags : int
      The OpenCV flag(s) to pass to the reader. Refer to the `OpenCV docs
      <https://docs.opencv.org/4.x/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56>`_
      for details.
  
  Returns
  -------
  ndimage : np.ndarray
      The decoded image as a numpy array.
docstr_tok: ["Read","an","image","from","the","ImageResource",".","Parameters","--","--","--","--","--","index",":","int",",","Ellipsis","If","int",",","read","the","index-th","image","from","the","ImageResource",".","If","``","...","``",",","read","all","images","from","the","ImageResource","and","stack","them","along","a","new",",","prepended",",","batch","dimension",".","If","None","(","default",")",",","use","``","index=0","``","if","the","image","contains","exactly","one","image","and","``","index=","...","``","otherwise",".","colorspace",":","str",",","int","The","colorspace","to","convert","into","after","loading","and","before","returning","the","image",".","If","None","(","default",")","keep","grayscale","images","as","is",",","convert","images","with","an","alpha","channel","to","``","RGBA","``","and","all","other","images","to","``","RGB","``",".","If","int",",","interpret","``","colorspace","``","as","one","of","OpenCVs","`","conversion","flags","<","https",":","\/\/docs.opencv.org\/4.x\/d8\/d01\/group__imgproc__color__conversions.html",">","`","_","and","use","it","for","conversion",".","If","str",",","convert","the","image","into","the","given","colorspace",".","Possible","string","values","are",":","``","``","RGB","''","``",",","``","``","BGR","''","``",",","``","``","RGBA","''","``",",","``","``","BGRA","''","``",",","``","``","GRAY","''","``",",","``","``","HSV","''","``",",","or","``","``","LAB","''","``",".","flags",":","int","The","OpenCV","flag","(","s",")","to","pass","to","the","reader",".","Refer","to","the","`","OpenCV","docs","<","https",":","\/\/docs.opencv.org\/4.x\/d4\/da8\/group__imgcodecs.html","#","ga288b8b3da0892bd651fce07b3bbd3a56",">","`","_","for","details",".","Returns","--","--","--","-","ndimage",":","np.ndarray","The","decoded","image","as","a","numpy","array","."]
code: def read(
      self,
      *,
      index: int = None,
      colorspace: Union[int, str] = None,
      flags: int = cv2.IMREAD_COLOR,
  ) -> np.ndarray:
      """Read an image from the ImageResource.
  
      Parameters
      ----------
      index : int, Ellipsis
          If int, read the index-th image from the ImageResource. If ``...``,
          read all images from the ImageResource and stack them along a new,
          prepended, batch dimension. If None (default), use ``index=0`` if
          the image contains exactly one image and ``index=...`` otherwise.
      colorspace : str, int
          The colorspace to convert into after loading and before returning
          the image. If None (default) keep grayscale images as is, convert
          images with an alpha channel to ``RGBA`` and all other images to
          ``RGB``. If int, interpret ``colorspace`` as one of OpenCVs
          `conversion flags
          <https://docs.opencv.org/4.x/d8/d01/group__imgproc__color__conversions.html>`_
          and use it for conversion. If str, convert the image into the given
          colorspace. Possible string values are: ``"RGB"``, ``"BGR"``,
          ``"RGBA"``, ``"BGRA"``, ``"GRAY"``, ``"HSV"``, or ``"LAB"``.
      flags : int
          The OpenCV flag(s) to pass to the reader. Refer to the `OpenCV docs
          <https://docs.opencv.org/4.x/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56>`_
          for details.
  
      Returns
      -------
      ndimage : np.ndarray
          The decoded image as a numpy array.
  
      """
  
      if index is None:
          n_images = cv2.imcount(self.file_handle, flags)
          index = 0 if n_images == 1 else ...
  
      if index is ...:
          retval, img = cv2.imreadmulti(self.file_handle, flags=flags)
          is_batch = True
      else:
          retval, img = cv2.imreadmulti(
              self.file_handle, index, 1, flags=flags
          )
          is_batch = False
  
      if retval is False:
          raise ValueError(
              f"Could not read index `{index}` from `{self.filename}`."
          )
  
      if img[0].ndim == 2:
          in_colorspace = "GRAY"
          out_colorspace = colorspace or "GRAY"
      elif img[0].shape[-1] == 4:
          in_colorspace = "BGRA"
          out_colorspace = colorspace or "RGBA"
      else:
          in_colorspace = "BGR"
          out_colorspace = colorspace or "RGB"
  
      if isinstance(colorspace, int):
          cvt_space = colorspace
      elif in_colorspace == out_colorspace.upper():
          cvt_space = None
      else:
          out_colorspace = out_colorspace.upper()
          cvt_space = getattr(
              cv2, f"COLOR_{in_colorspace}2{out_colorspace}"
          )
  
      if cvt_space is not None:
          img = np.stack([cv2.cvtColor(x, cvt_space) for x in img])
      else:
          img = np.stack(img)
  
      return img if is_batch else img[0]
  
file_path: imageio/imageio/plugins/opencv.py
imports: import warnings
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Union
  import cv2
  import numpy
  from ..core import Request
  from ..core.request import URI_BYTES, InitializationError, IOMode
  from ..core.v3_plugin_api import ImageProperties, PluginV3
  from ..typing import ArrayLike
label_desc: Use image node_id 2 for calling the OpenCVPlugin obj's underlying member method code with example usage: obj.read() and returns: unknown