
    2Vh                         d dl Zd dlmZ d dlmZ d dlmZ d dlmZ 	 d dl	Z	 ed      	 	 	 	 	 	 d	d       Zd Zy# e
$ r dZ	Y "w xY w)
    N)backend)ops)keras_export)convert_formatz'keras.visualization.draw_bounding_boxesc	                 V   t         t        d      |xs i }|xs |}|xs t        j                         }t	        j
                  |       }	t        |	      dk7  rt        d|	       t        |t              st        d| dt        |             d|vsd|vrt        d	|       |d
k(  rd}
d}nd}
d}|	|
   }|	|   }|j                         }t        ||d||      }t	        j                  |       j                  d      } t	        j                  |d         }t	        j                  |d         }d|v rt	        j                  |d         }nd}g }| j
                  d   }t!        |      D ]#  }| |   }||   }||   }t!        |j
                  d         D ]  }||   j                  d      \  }}}}||   j                  d      }|dk(  r6t#        |      t#        |      t#        |      t#        |      f\  }}}}t#        |      }t        j$                  |||f||f||       ||v s||   }|||   |   }| d|d}t'        ||||      \  }} t        j(                  |||| ft         j*                  |||        |j-                  |       & t/        j0                  |d      S )a!
  Draws bounding boxes on images.

    This function draws bounding boxes on a batch of images.  It supports
    different bounding box formats and can optionally display class labels
    and confidences.

    Args:
        images: A batch of images as a 4D tensor or NumPy array. Shape should be
            `(batch_size, height, width, channels)`.
        bounding_boxes: A dictionary containing bounding box data.  Should have
            the following keys:
            - `boxes`: A tensor or array of shape `(batch_size, num_boxes, 4)`
               containing the bounding box coordinates in the specified format.
            - `labels`: A tensor or array of shape `(batch_size, num_boxes)`
              containing the class labels for each bounding box.
            - `confidences` (Optional): A tensor or array of shape
               `(batch_size, num_boxes)` containing the confidence scores for
               each bounding box.
        bounding_box_format: A string specifying the format of the bounding
            boxes. Refer [keras-io](TODO)
        class_mapping: A dictionary mapping class IDs (integers) to class labels
            (strings).  Used to display class labels next to the bounding boxes.
            Defaults to None (no labels displayed).
        color: A tuple or list representing the RGB color of the bounding boxes.
            For example, `(255, 0, 0)` for red. Defaults to `(128, 128, 128)`.
        line_thickness: An integer specifying the thickness of the bounding box
            lines. Defaults to `2`.
        text_thickness: An integer specifying the thickness of the text labels.
            Defaults to `1`.
        font_scale: A float specifying the scale of the font used for text
            labels. Defaults to `1.0`.
        data_format: A string, either `"channels_last"` or `"channels_first"`,
            specifying the order of dimensions in the input images. Defaults to
            the `image_data_format` value found in your Keras config file at
            `~/.keras/keras.json`. If you never set it, then it will be
            "channels_last".

    Returns:
        A NumPy array of the annotated images with the bounding boxes drawn.
        The array will have the same shape as the input `images`.

    Raises:
        ValueError: If `images` is not a 4D tensor/array, if `bounding_boxes` is
            not a dictionary, or if `bounding_boxes` does not contain `"boxes"`
            and `"labels"` keys.
        TypeError: If `bounding_boxes` is not a dictionary.
        ImportError: If `cv2` (OpenCV) is not installed.
    Nz|The `draw_bounding_boxes` function requires the `cv2` package  (OpenCV). Please install it with `pip install opencv-python`.   z;`images` must be batched 4D tensor. Received: images.shape=z<`bounding_boxes` should be a dict. Received: bounding_boxes=z	 of type boxeslabelsza`bounding_boxes` should be a dict containing 'boxes' and 'labels' keys. Received: bounding_boxes=channels_lastxyxyuint8confidencesr   int32z | z.2f)imgtextorgfontFace	fontScalecolor	thickness)axis)cv2ImportErrorr   image_data_formatr   shapelen
ValueError
isinstancedict	TypeErrortypecopyr   convert_to_numpyastyperangeint	rectangle_find_text_locationputTextFONT_HERSHEY_SIMPLEXappendnpstack)!imagesbounding_boxesbounding_box_formatclass_mappingr   line_thicknesstext_thickness
font_scaledata_formatimages_shapeh_axisw_axisheightwidthr	   r
   r   result
batch_sizei_image_box_classbox_ix1y1x2y2clabelconffont_x1font_y1s!                                    [/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/visualization/draw_bounding_boxes.pydraw_bounding_boxesrO      s)   z {M
 	

 "'RM(.  <!:!:!<K99V$L
<A&&2^5
 	
 nd+((6'7yN#$&
 	

 n$(F77E6FH
 	
 o%&!F E#((*N#+VVUN
 !!&)009F  !89E!!.":;F&**>-+HIFaJ:  Qx4::a=) 	E!%[//8NBBu$$W-ABw Wc"gs2wB?NBBAAMM&2r(RHe^LM!%a(*&q>%0D$gSc
3E#6J$   '* 55(,'	8 	fA B 88F##    c                 z    t        |dz        }|dz
  }|d|z  z
  dkD  r| |dz
  fS |}d}| |z   |d|z  z   |z   |z   fS )N         r      )r)   )xyr7   r   font_heighttarget_yline_offsetstatic_offsets           rN   r+   r+      sk    j2o&K1uH1{?#a'!a%xKM 	
M	Q_+m; rP   )N)   r\   r\   rT      g      ?N)numpyr/   	keras.srcr   r   keras.src.api_exportr   Lkeras.src.layers.preprocessing.image_preprocessing.bounding_boxes.convertersr   r   r   rO   r+    rP   rN   <module>rc      sk       -
 78
 
Q$ 9Q$hs  
Cs   ; AA