Ë
    \;j:/  ã                   óŽ   — d Z ddlmZmZmZ ddlZddlZddl	m
Z ddlZd„ Zd„ Zd„ Zd„ Zd„ Zd	„ Zdd
„Zdd„Zd„ Zd„ Zd„ Zdd„Zy)z.Utility functions used in augmentable modules.é    )Úprint_functionÚabsolute_importÚdivisionNc                 ó  — t        j                  | «      rt        j                  | «      S g }| D ][  }t        j                  |«      r%|j	                  t        j                  |«      «       Œ=|j	                  |j                  «       «       Œ] |S ©N)ÚiaÚis_np_arrayÚnpÚcopyÚappendÚdeepcopy)ÚaugmentablesÚresultÚaugmentables      úbG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\imgaug/augmentables/utils.pyÚcopy_augmentablesr   
   si   € Ü	‡~�~�lÔ#Ü�w‰w�|Ó$Ð$à€FÛ#ˆÜ�>‰>˜+Ô&Ø�M‰Mœ"Ÿ'™' +Ó.Õ/à�M‰M˜+×.Ñ.Ó0Õ1ð	 $ð
 €Mó    c                 óà  — | €y t        j                  | «      st        j                  | «      r| S t        | t        «      r| D �cg c]  }t        |«      ‘Œ c}S t        | t        «      r"t        | D �cg c]  }t        |«      ‘Œ c}«      S t        j                  | «      rt        j                  | «      S t        | d«      r| j                  «       S t        j                  | «      S c c}w c c}w )Nr   )r   Úis_single_numberÚ	is_stringÚ
isinstanceÚlistÚdeepcopy_fastÚtupler	   r
   r   Úhasattrr   Úcopylib)ÚobjÚels     r   r   r      s¾   € Ø
€{ØÜ	×Ñ˜3Ô¤2§<¡<°Ô#4Øˆ
Ü�#”tÔÙ,/Ó0©C b”˜bÕ!¨CÑ0Ð0Ü�#”uÔÜ±#Ó6±#¨B”m BÕ'°#Ñ6Ó7Ð7Ü	‡~�~�cÔÜ�w‰w�s‹|ÐÜˆs�JÔØ�|‰|‹~ÐÜ×Ñ˜CÓ Ð ùò 1ùâ6s   ÁC&Á2C+c                 ó�   — t        | t        «      r| S t        j                  | «      sJ dt	        | «      ›d�«       ‚| j
                  S )a  Normalize a shape ``tuple`` or ``array`` to a shape ``tuple``.

    Parameters
    ----------
    shape : tuple of int or ndarray
        The input to normalize. May optionally be an array.

    Returns
    -------
    tuple of int
        Shape ``tuple``.

    z%Expected tuple of ints or array, got Ú.)r   r   r   r	   ÚtypeÚshape)r"   s    r   Únormalize_shaper#   )   sB   € ô �%œÔØˆÜ�>‰>˜%Ô ñ EÜ6:¸5µkÐCóEÐ à�;‰;Ðr   c                 óò  — t        |«      }t        |«      }|dd |dd k(  r| S |dd \  }}|dd \  }}t        ||||fD �cg c]  }|dkD  ‘Œ	 c}«      }|sJ d|›d|›d�«       ‚| }	t        j                  | «      r| j                  j
                  dk7  r2t        j                  | «      j                  t        j                  «      }	|	dd…df   |z  |z  |	dd…df<   |	dd…df   |z  |z  |	dd…df<   |	S c c}w )	aò  Project coordinates from one image shape to another in-place.

    This performs a relative projection, e.g. a point at ``60%`` of the old
    image width will be at ``60%`` of the new image width after projection.

    Added in 0.4.0.

    Parameters
    ----------
    coords : ndarray or list of tuple of number
        Coordinates to project.
        Either an ``(N,2)`` numpy array or a ``list`` containing ``(x,y)``
        coordinate ``tuple`` s.

    from_shape : tuple of int or ndarray
        Old image shape.

    to_shape : tuple of int or ndarray
        New image shape.

    Returns
    -------
    ndarray
        Projected coordinates as ``(N,2)`` ``float32`` numpy array.
        This function may change the input data in-place.

    r   é   zBExpected from_shape and to_shape to not contain zeros. Got shapes z (from_shape) and z (to_shape).ÚfNé   )
r#   Úallr   r	   ÚdtypeÚkindr
   ÚarrayÚastypeÚfloat32)
ÚcoordsÚ
from_shapeÚto_shapeÚfrom_heightÚ
from_widthÚ	to_heightÚto_widthÚvÚno_zeros_in_shapesÚcoords_projs
             r   Úproject_coords_r8   >   s*  € ô8 ! Ó,€JÜ˜xÓ(€HØ�!�A€˜( 1 Q˜-Ò'Øˆà(¨¨1˜oÑ€K�Ø" 1 Q˜-Ñ€Iˆxô 	˜[¨*°iÀÑJÓKÑJ�qˆQ�‹UÐJÑKÓLð áñ Gâ0:ºHð	FóGÐð €KÜ�>‰>˜&Ô! V§\¡\×%6Ñ%6¸#Ò%=Ü—h‘h˜vÓ&×-Ñ-¬b¯j©jÓ9ˆà$¢Q¨ TÑ*¨ZÑ7¸8ÑC€K’�1�ÑØ$¢Q¨ TÑ*¨[Ñ8¸IÑE€K’�1�ÑàÐùò Ls   ÁC4c                 óp   — t        j                  | «      rt        j                  | «      } t	        | ||«      S )aš  Project coordinates from one image shape to another.

    This performs a relative projection, e.g. a point at ``60%`` of the old
    image width will be at ``60%`` of the new image width after projection.

    Parameters
    ----------
    coords : ndarray or list of tuple of number
        Coordinates to project.
        Either an ``(N,2)`` numpy array or a ``list`` containing ``(x,y)``
        coordinate ``tuple`` s.

    from_shape : tuple of int or ndarray
        Old image shape.

    to_shape : tuple of int or ndarray
        New image shape.

    Returns
    -------
    ndarray
        Projected coordinates as ``(N,2)`` ``float32`` numpy array.

    )r   r	   r
   r   r8   )r.   r/   r0   s      r   Úproject_coordsr:   r   s,   € ô2 
‡~�~�fÔÜ—‘˜“ˆä˜6 :¨xÓ8Ð8r   c                 óò   — |dk  rg S | \  }}|\  }}t        j                  ||z
  ||z
  g«      }|d|z   z  }t        j                  |«      D �	cg c]  }	||	dz   |d   z  z   ||	dz   |d   z  z   f‘Œ  c}	S c c}	w )aú  Interpolate ``N`` points on a line segment.

    Parameters
    ----------
    point_a : iterable of number
        Start point of the line segment, given as ``(x,y)`` coordinates.

    point_b : iterable of number
        End point of the line segment, given as ``(x,y)`` coordinates.

    nb_steps : int
        Number of points to interpolate between `point_a` and `point_b`.

    Returns
    -------
    list of tuple of number
        The interpolated points.
        Does not include `point_a`.

    r'   r   )r
   r-   ÚsmÚxrange)
Úpoint_aÚpoint_bÚnb_stepsÚx1Úy1Úx2Úy2ÚvecÚ	step_sizeÚis
             r   Úinterpolate_point_pairrH   ’   s©   € ð* �!‚|Øˆ	Ø�F€BˆØ�F€BˆÜ
�*‰*�b˜2‘g˜r B™wÐ'Ó
(€CØ�q˜8‘|Ñ$€Iô �9‰9�XÔó ñ ð ð 
ˆq�1‰u˜	 !™Ñ$Ñ	$ b¨A°©E°Y¸q±\Ñ+AÑ&AÒBàñ ð  ùò  s   Á#A4c           	      óò   — t        | «      dk  r| S |rt        | «      | d   gz   } g }t        | dd | dd «      D ]%  \  }}|j                  |gt	        |||«      z   «       Œ' |s|j                  | d   «       |S )a7  Interpolate ``N`` on each line segment in a line string.

    Parameters
    ----------
    points : iterable of iterable of number
        Points on the line segments, each one given as ``(x,y)`` coordinates.
        They are assumed to form one connected line string.

    nb_steps : int
        Number of points to interpolate on each individual line string.

    closed : bool, optional
        If ``True`` the output contains the last point in `points`.
        Otherwise it does not (but it will contain the interpolated points
        leading to the last point).

    Returns
    -------
    list of tuple of number
        Coordinates of `points`, with additional `nb_steps` new points
        interpolated between each point pair. If `closed` is ``False``,
        the last point in `points` is not returned.

    r'   r   Néÿÿÿÿ)Úlenr   ÚzipÚextendrH   r   )Úpointsr@   ÚclosedÚpoints_interpr>   r?   s         r   Úinterpolate_pointsrQ   ³   s—   € ô2 ˆ6ƒ{�aÒØˆÙÜ�f“ ¨¡ Ñ+ˆØ€MÜ  s¨ ¨V°A°B¨ZÖ8Ñˆ�Ø×ÑØˆIÜ$ W¨g°xÓ@ñAõ	
ð 9ñ
 Ø×Ñ˜V B™ZÔ(ð Ðr   c           	      ó”  — |dkD  sJ d|fz  «       ‚t        | «      dk  r| S |rt        | «      | d   gz   } g }t        | dd | dd «      D ]f  \  }}t        j                  |d   |d   z
  dz  |d   |d   z
  dz  z   «      }t        ||z  dz
  «      }|j                  |gt        |||«      z   «       Œh |s|j                  | d   «       |S )aƒ  Interpolate points with distance ``d`` on a line string.

    For a list of points ``A, B, C``, if the distance between ``A`` and ``B``
    is greater than `max_distance`, it will place at least one point between
    ``A`` and ``B`` at ``A + max_distance * (B - A)``. Multiple points can
    be placed between the two points if they are far enough away from each
    other. The process is repeated for ``B`` and ``C``.

    Parameters
    ----------
    points : iterable of iterable of number
        Points on the line segments, each one given as ``(x,y)`` coordinates.
        They are assumed to form one connected line string.

    max_distance : number
        Maximum distance between any two points in the result.

    closed : bool, optional
        If ``True`` the output contains the last point in `points`.
        Otherwise it does not (but it will contain the interpolated points
        leading to the last point).

    Returns
    -------
    list of tuple of number
        Coordinates of `points`, with interpolated points added to the
        iterable. If `closed` is ``False``, the last point in `points` is not
        returned.

    r   z3Expected max_distance to have a value >0, got %.8f.r'   NrJ   r%   )	rK   r   rL   r
   ÚsqrtÚintrM   rH   r   )rN   Úmax_distancerO   rP   r>   r?   Údistr@   s           r   Ú"interpolate_points_by_max_distancerW   Ý   s  € ð> ˜!Òð Ø=ØðAñ 	óÐô ˆ6ƒ{�aÒØˆÙÜ�f“ ¨¡ Ñ+ˆØ€MÜ  s¨ ¨V°A°B¨ZÖ8Ñˆ�Ü�w‰wØ�Q‰Z˜' !™*Ñ$¨Ñ*Ø�q‰z˜G A™JÑ&¨1Ñ,ñ-ó.ˆô ˜˜|Ñ+¨qÑ0Ó1ˆØ×ÑØˆIÜ$ W¨g°xÓ@ñAõ	Bð 9ñ Ø×Ñ˜V B™ZÔ(ØÐr   c                 ó–   — t        | t        «      s| j                  «       S g }| D ]!  }|j                  |j                  «       «       Œ# |S )aÐ  Convert coordinate-based augmentables to KeypointsOnImage instances.

    Added in 0.4.0.

    Parameters
    ----------
    cbaois : list of imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.PolygonsOnImage or list of imgaug.augmentables.bbs.LineStringsOnImage or imgaug.augmentables.bbs.BoundingBoxesOnImage or imgaug.augmentables.bbs.PolygonsOnImage or imgaug.augmentables.bbs.LineStringsOnImage
        Coordinate-based augmentables to convert, e.g. bounding boxes.

    Returns
    -------
    list of imgaug.augmentables.kps.KeypointsOnImage or imgaug.augmentables.kps.KeypointsOnImage
        ``KeypointsOnImage`` instances containing the coordinates of input
        `cbaois`.

    )r   r   Úto_keypoints_on_imager   )ÚcbaoisÚkpsoisÚcbaois      r   Úconvert_cbaois_to_kpsoisr]     sF   € ô" �fœdÔ#Ø×+Ñ+Ó-Ð-à€FÛˆØ�‰�e×1Ñ1Ó3Õ4ð à€Mr   c                 ó  — t        | t        «      s?t        |t        «      rJ dt        |j                  «      z  f«       ‚| j	                  |«      S g }t        | |«      D ]'  \  }}|j	                  |«      }|j                  |«       Œ) |S )a  Invert the output of :func:`convert_to_cbaois_to_kpsois` in-place.

    This function writes in-place into `cbaois`.

    Added in 0.4.0.

    Parameters
    ----------
    cbaois : list of imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.PolygonsOnImage or list of imgaug.augmentables.bbs.LineStringsOnImage or imgaug.augmentables.bbs.BoundingBoxesOnImage or imgaug.augmentables.bbs.PolygonsOnImage or imgaug.augmentables.bbs.LineStringsOnImage
        Original coordinate-based augmentables before they were converted,
        i.e. the same inputs as provided to :func:`convert_to_kpsois`.

    kpsois : list of imgaug.augmentables.kps.KeypointsOnImages or imgaug.augmentables.kps.KeypointsOnImages
        Keypoints to convert back to the types of `cbaois`, i.e. the outputs
        of :func:`convert_cbaois_to_kpsois`.

    Returns
    -------
    list of imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.PolygonsOnImage or list of imgaug.augmentables.bbs.LineStringsOnImage or imgaug.augmentables.bbs.BoundingBoxesOnImage or imgaug.augmentables.bbs.PolygonsOnImage or imgaug.augmentables.bbs.LineStringsOnImage
        Parameter `cbaois`, with updated coordinates and shapes derived from
        `kpsois`. `cbaois` is modified in-place.

    zFExpected non-list for `kpsois` when `cbaois` is non-list. Got type %s.)r   r   r!   Ú__name__Úinvert_to_keypoints_on_image_rL   r   )rZ   r[   r   r\   ÚkpsoiÚcbaoi_recovereds         r   Ú invert_convert_cbaois_to_kpsois_rc   +  s�   € ô0 �fœdÔ#Ü˜f¤dÔ+ð 	7ðÜ" 6§?¡?Ó3ñ5ð.7ó 	7Ð+ð ×3Ñ3°FÓ;Ð;à€FÜ˜F FÖ+‰ˆˆuØ×=Ñ=¸eÓDˆØ�‰�oÕ&ð ,ð €Mr   c                 óŠ   — | j                   D �cg c]"  }|j                  | j                  «      |k  r|‘Œ$ c}| _         | S c c}w r   )ÚitemsÚcompute_out_of_image_fractionr"   )r\   ÚfractionÚitems      r   Ú_remove_out_of_image_fraction_ri   R  sJ   € àŸšóGÙ$�Ø×-Ñ-¨e¯k©kÓ:¸XÒEò 	˜ñG€E„Kð €LùòGs   �'A c                 óê   — t        ||||fD �cg c]  }|du‘Œ c}«      rLt        j                  d|›d|›d|›d|›d�	d¬«       |�|nd	}|�|nd	}|�|nd	}|�|nd	}| |z   |z
  } ||z   |z
  }| |fS c c}w )
zCNormalize ``shift()`` arguments to x, y and handle deprecated args.Nz Got one of the arguments `top` (z), `right` (z), `bottom` (z), `left` (zC) in a shift() call. These are deprecated. Use `x` and `y` instead.é   )Ú
stacklevelr   )Úanyr   Úwarn_deprecated)ÚxÚyÚtopÚrightÚbottomÚleftr5   s          r   Ú_normalize_shift_argsru   Z  s¦   € ä
 C¨°¸Ñ#=Ó>Ñ#=˜aˆA�TŠMÐ#=Ñ>Ô?Ü
×Òò ’UšF¢Dð*ð õ	ð �_‰c¨!ˆØÐ*‘°ˆØ!Ð-‘°1ˆØÐ'‰t¨QˆØ�‰H�uÑˆØ�‰G�fÑˆØˆaˆ4€Kùò ?s   ŽA0)T)NNNN)Ú__doc__Ú
__future__r   r   r   r   r   Únumpyr
   Ú	six.movesÚmovesr<   Úimgaugr   r   r   r#   r8   r:   rH   rQ   rW   r]   rc   ri   ru   © r   r   Ú<module>r}      s\   ðÙ 4ß @Ñ @Û Û Ý Û ò
ò!ò"ò*1òh9ò@ óB'óT1òhò4#òNôr   