+
    ?im-                         R t ^ RIt^ RIHt ^ RIHtHtHtHtH	t	 ^ RI
t
^ RIt^RIHt ^RIHtHtHt ^RIHtHt ^RIHt  ! R R	]4      tR# )
ag  Read/Write images using OpenCV.

Backend Library: `OpenCV <https://opencv.org/>`_

This plugin wraps OpenCV (also known as ``cv2``), a popular image processing
library. Currently, it exposes OpenCVs image reading capability (no video or GIF
support yet); however, this may be added in future releases.

Methods
-------
.. note::
    Check the respective function for a list of supported kwargs and their
    documentation.

.. autosummary::
    :toctree:

    OpenCVPlugin.read
    OpenCVPlugin.iter
    OpenCVPlugin.write
    OpenCVPlugin.properties
    OpenCVPlugin.metadata

Pixel Formats (Colorspaces)
---------------------------

OpenCV is known to process images in BGR; however, most of the python ecosystem
(in particular matplotlib and other pydata libraries) use the RGB. As such,
images are converted to RGB, RGBA, or grayscale (where applicable) by default.

N)Path)AnyDictListOptionalUnionRequest)	URI_BYTESInitializationErrorIOMode)ImagePropertiesPluginV3)	ArrayLikec                      a a ] tR t^.t oV3R lV 3R lltRRRRR]P                  /V3R lR lltR]P                  3V3R	 lR
 lltRV3R lR llt	RR]P                  3V3R lR llt
RV3R lR lltRtVtV ;t# )OpenCVPluginc                $   < V ^8  d   QhRS[ RR/# )   requestreturnNr   )format__classdict__s   "T/var/www/html/photoedit/myenv/lib/python3.14/site-packages/imageio/plugins/opencv.py__annotate__OpenCVPlugin.__annotate__/   s     S S SD S    c                *  < \         SV `  V4       VP                  4       V n        VP                  \
        J d	   R V n        MVP                  V n        VP                  P                  pV\        P                  8X  d@   \        P                  ! V P                  4      '       g   \        RV P                   R24      hV\        P                  8X  dB   \        P                   ! V P                  4      '       g   \        RV P                   R24      hR# R# )z<bytes>zOpenCV can't read ``.zOpenCV can't write to `N)super__init__get_local_filenamefile_handle	_uri_typer
   filenameraw_urimodeio_moder   readcv2haveImageReaderr   writehaveImageWriter)selfr   r%   	__class__s   && r   r   OpenCVPlugin.__init__/   s    !"557	)%DM#OODM||##6;;s':':4;K;K'L'L%(;DMM?"&MNNV\\!#*=*=d>N>N*O*O%(?b&QRR +P!r   indexN
colorspaceflagsc                \   < V ^8  d   QhRS[ RS[S[ S[3,          RS[ RS[P                  /# r   r/   r0   r1   r   )intr   strnpndarray)r   r   s   "r   r   r   >   sG     K+ K+ K+ #s(O	K+
 K+ 
K+r   c          	        Vf-   \         P                  ! V P                  V4      pV^8X  d   ^ MRpVRJ d(   \         P                  ! V P                  VR7      w  rVRpM(\         P                  ! V P                  V^VR7      w  rVRpVRJ d   \	        RV RV P
                   R24      hV^ ,          P                  ^8X  d   R	pT;'       g    R	p	M<V^ ,          P                  R,          ^8X  d   R
pT;'       g    Rp	MRpT;'       g    Rp	\        V\        4      '       d   Tp
M=WP                  4       8X  d   Rp
M&V	P                  4       p	\        \         RV RV	 24      p
V
e<   \        P                  ! V Uu. uF  p\         P                  ! W4      NK  	  up4      pM\        P                  ! V4      pV'       d   V# V^ ,          # u upi )a  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.

N.)r1   TFzCould not read index `z` from `r   GRAYBGRARGBABGRRGBCOLOR_2)r(   imcountr!   imreadmulti
ValueErrorr#   ndimshape
isinstancer4   uppergetattrr6   stackcvtColor)r,   r/   r0   r1   n_imagesretvalimgis_batchin_colorspaceout_colorspace	cvt_spacexs   &$$$        r   r'   OpenCVPlugin.read>   s   L ={{4#3#3U;H!QACEC<//$*:*:%HKFH//$*:*:E1ERKFHU?5eWHT]]OSUVWWq6;;!"M'116NV\\"""M'116N!M'005Nj#&&"I2244I+113Nvm_An=M%NOI ((D1CLL6DEC((3-Cs*CF*	 Es   9G	c                V   < V ^8  d   QhRS[ S[S[3,          RS[RS[P                  /# )r   r0   r1   r   )r   r4   r5   r6   r7   )r   r   s   "r   r   r      s:     K K#s(OK K 
	Kr   c              #     "   \        \        P                  ! V P                  4      4       F  pV P	                  W2VR7      x  K  	  R# 5i)a  Yield images from the ImageResource.

Parameters
----------
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.

Yields
------
ndimage : np.ndarray
    The decoded image as a numpy array.

r/   r1   r0   N)ranger(   rA   r!   r'   )r,   r0   r1   idxs   &&& r   iterOpenCVPlugin.iter   s8     < T%5%567C))#z)JJ 8s   AA
c          	      x   < V ^8  d   QhRS[ S[S[S[,          3,          RS[RS[S[,          RS[S[,          /# )r   ndimagerN   paramsr   )r   r   r   boolr4   r   bytes)r   r   s   "r   r   r      sI     87 87y$y/1287 87 S		87
 
%87r   c                   \        V\        4      '       d   \        P                  ! V^ R7      pMV'       g
   VR,          pV^ ,          P                  ^8X  d   ^pMV^ ,          P
                  R,          pV^8X  d   V Uu. uF  qUNK  	  ppMpV^8X  d6   V Uu. uF(  p\        P                  ! V\        P                  4      NK*  	  ppM4V Uu. uF(  p\        P                  ! V\        P                  4      NK*  	  pp\        P                  ! V P                  Wc4      pVRJ d   \        R4      hV P                  P                  \        8X  d$   \!        V P                  4      P#                  4       # R# u upi u upi u upi )a  Save an ndimage in the ImageResource.

Parameters
----------
ndimage : ArrayLike, List[ArrayLike]
    The image data that will be written to the file. It is either a
    single image, a batch of images, or a list of images.
is_batch : bool
    If True, the provided ndimage is a batch of images. If False (default), the
    provided ndimage is a single image. If the provided ndimage is a list of images,
    this parameter has no effect.
params : List[int]
    A list of parameters that will be passed to OpenCVs imwrite or
    imwritemulti functions. Possible values are documented in the
    `OpenCV documentation
    <https://docs.opencv.org/4.x/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce>`_.

Returns
-------
encoded_image : bytes, None
    If the ImageResource is ``"<bytes>"`` the call to write returns the
    encoded image as a bytes string. Otherwise it returns None.

)axisNFzOpenCV failed to write.)N.r@   )rF   listr6   rI   rD   rE   r(   rJ   COLOR_RGBA2BGRACOLOR_RGB2BGRimwritemultir!   IOErrorr   r"   r
   r   
read_bytes)r,   r\   rN   r]   
n_channelsrR   ndimage_cv2rL   s   &&&&    r   r*   OpenCVPlugin.write   s0   > gt$$hhwQ/Gi(G1:??aJ ))"-J?&-.g1gK.K1_IPQA3<<3+>+>?KQKGNOw!3<<3+<+<=wKO!!$"2"2KHU? 344<<!!Y.(()4466 / /QOs   
E4.E9.E>c                H   < V ^8  d   QhRS[ RS[S[ S[3,          RS[ RS[/# r3   )r4   r   r5   r   )r   r   s   "r   r   r      sA     >Q >Q>Q #s(O>Q 	>Q
 
>Qr   c                   Vf(   \         P                  ! V P                  V4      pV^8  pM0V\        J d%   \         P                  ! V P                  V4      pRpMRpV'       d;   V P	                  ^ W2R7      p\        X.VP                  O5VP                  VRR7      # V P	                  WVR7      p\        VP                  VP                  RR7      # )af  Standardized image metadata.

Parameters
----------
index : int, Ellipsis
    If int, get the properties of the index-th image in the
    ImageResource. If ``...``, get the properties of the image stack
    that contains all images. 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
-------
props : ImageProperties
    A dataclass filled with standardized image metadata.

Notes
-----
Reading properties with OpenCV involves decoding pixel data, because
OpenCV doesn't provide a direct way to access metadata.

TFrV   )rE   dtyperK   rN   )rE   rm   rN   )r(   rA   r!   Ellipsisr'   r   rE   rm   )r,   r/   r0   r1   rK   rN   rM   s   &&&&   r   
propertiesOpenCVPlugin.properties   s    T ={{4#3#3U;H!|Hh{{4#3#3U;HHH ))!5)HC",#)),ii!	  iieZiHSYYcii%PPr   c                B   < V ^8  d   QhRS[ RS[RS[S[S[3,          /# )r   r/   exclude_appliedr   )r4   r^   r   r5   r   )r   r   s   "r   r   r   &  s-      26	c3hr   c                L    \         P                  ! R\        4       \        4       # )a  Format-specific metadata.

.. warning::
    OpenCV does not support reading metadata. When called, this function
    will raise a ``NotImplementedError``.

Parameters
----------
index : int
    This parameter has no effect.
exclude_applied : bool
    This parameter has no effect.

z)OpenCV does not support reading metadata.)warningswarnUserWarningdict)r,   r/   rr   s   &&&r   metadataOpenCVPlugin.metadata&  s    $ 	A;Ovr   )r!   r#   )FN)NT)__name__
__module____qualname____firstlineno__r   r(   IMREAD_COLORr'   rY   r*   ro   rx   __static_attributes____classdictcell____classcell__)r-   r   s   @@r   r   r   .   s     S SK+ K+ '+	K+
 %%K+ K+^ '+%%K KB87 87x &*%%	>Q >Q@  r   r   )__doc__rt   pathlibr   typingr   r   r   r   r   r(   numpyr6   corer	   core.requestr
   r   r   core.v3_plugin_apir   r   r   r    r   r   <module>r      s<   @   3 3 
   A A : K8 Kr   