Ë
    ÿ[;jÊ4  ã                   ó.  — d dl ZddlmZmZmZmZ ddlmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ dd	lmZ  ej(                  d
«      Zg d¢Z edd«      D ]3  Z ee ee«          e ee«         dz   «      D ]  Zdedez   dez   f<   Œ Œ5  G d„ dee«      Zy)é    Né   )ÚFeatureDetectorÚDescriptorExtractorÚ_mask_border_keypointsÚ_prepare_grayscale_input_2Dé   )Úcorner_fastÚcorner_orientationsÚcorner_peaksÚcorner_harris)Úpyramid_gaussian)Úcheck_nD)ÚNP_COPY_IF_NEEDED)Ú	_orb_loop)é   r   )é   r   r   r   é   r   r   é   r   é   é   é
   é	   é   é   é   iñÿÿÿé   r   c                   óH   — e Zd ZdZ	 	 	 	 	 	 d
d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)ÚORBa  Oriented FAST and rotated BRIEF feature detector and binary descriptor
    extractor.

    Parameters
    ----------
    n_keypoints : int, optional
        Number of keypoints to be returned. The function will return the best
        `n_keypoints` according to the Harris corner response if more than
        `n_keypoints` are detected. If not, then all the detected keypoints
        are returned.
    fast_n : int, optional
        The `n` parameter in `skimage.feature.corner_fast`. Minimum number of
        consecutive pixels out of 16 pixels on the circle that should all be
        either brighter or darker w.r.t test-pixel. A point c on the circle is
        darker w.r.t test pixel p if ``Ic < Ip - threshold`` and brighter if
        ``Ic > Ip + threshold``. Also stands for the n in ``FAST-n`` corner
        detector.
    fast_threshold : float, optional
        The ``threshold`` parameter in ``feature.corner_fast``. Threshold used
        to decide whether the pixels on the circle are brighter, darker or
        similar w.r.t. the test pixel. Decrease the threshold when more
        corners are desired and vice-versa.
    harris_k : float, optional
        The `k` parameter in `skimage.feature.corner_harris`. Sensitivity
        factor to separate corners from edges, typically in range ``[0, 0.2]``.
        Small values of `k` result in detection of sharp corners.
    downscale : float, optional
        Downscale factor for the image pyramid. Default value 1.2 is chosen so
        that there are more dense scales which enable robust scale invariance
        for a subsequent feature description.
    n_scales : int, optional
        Maximum number of scales from the bottom of the image pyramid to
        extract the features from.

    Attributes
    ----------
    keypoints : (N, 2) array
        Keypoint coordinates as ``(row, col)``.
    scales : (N,) array
        Corresponding scales.
    orientations : (N,) array
        Corresponding orientations in radians.
    responses : (N,) array
        Corresponding Harris corner responses.
    descriptors : (Q, `descriptor_size`) array of dtype bool
        2D array of binary descriptors of size `descriptor_size` for Q
        keypoints after filtering out border keypoints with value at an
        index ``(i, j)`` either being ``True`` or ``False`` representing
        the outcome of the intensity comparison for i-th keypoint on j-th
        decision pixel-pair. It is ``Q == np.sum(mask)``.

    References
    ----------
    .. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski
          "ORB: An efficient alternative to SIFT and SURF"
          http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf

    Examples
    --------
    >>> from skimage.feature import ORB, match_descriptors
    >>> img1 = np.zeros((100, 100))
    >>> img2 = np.zeros_like(img1)
    >>> rng = np.random.default_rng(19481137)  # do not copy this value
    >>> square = rng.random((20, 20))
    >>> img1[40:60, 40:60] = square
    >>> img2[53:73, 53:73] = square
    >>> detector_extractor1 = ORB(n_keypoints=5)
    >>> detector_extractor2 = ORB(n_keypoints=5)
    >>> detector_extractor1.detect_and_extract(img1)
    >>> detector_extractor2.detect_and_extract(img2)
    >>> matches = match_descriptors(detector_extractor1.descriptors,
    ...                             detector_extractor2.descriptors)
    >>> matches
    array([[0, 0],
           [1, 1],
           [2, 2],
           [3, 4],
           [4, 3]])
    >>> detector_extractor1.keypoints[matches[:, 0]]
    array([[59. , 59. ],
           [40. , 40. ],
           [57. , 40. ],
           [46. , 58. ],
           [58.8, 58.8]])
    >>> detector_extractor2.keypoints[matches[:, 1]]
    array([[72., 72.],
           [53., 53.],
           [70., 53.],
           [59., 71.],
           [72., 72.]])

    c                 óž   — || _         || _        || _        || _        || _        || _        d | _        d | _        d | _        d | _	        d | _
        y )N)Ú	downscaleÚn_scalesÚn_keypointsÚfast_nÚfast_thresholdÚharris_kÚ	keypointsÚscalesÚ	responsesÚorientationsÚdescriptors)Úselfr    r!   r"   r#   r$   r%   s          ú\G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\skimage/feature/orb.pyÚ__init__zORB.__init__w   sU   € ð #ˆŒØ ˆŒØ&ˆÔØˆŒØ,ˆÔØ ˆŒàˆŒØˆŒØˆŒØ ˆÔØˆÕó    c                 óv   — t        |«      }t        t        || j                  dz
  | j                  d ¬«      «      S )Nr   )Úchannel_axis)r   Úlistr   r!   r    )r+   Úimages     r,   Ú_build_pyramidzORB._build_pyramid�   s7   € Ü+¨EÓ2ˆÜÜØ�t—}‘} qÑ(¨$¯.©.Àtôó
ð 	
r.   c                 óÚ  — |j                   }t        || j                  | j                  «      }t	        |d¬«      }t        |«      dk(  rDt        j                  d|¬«      t        j                  d|¬«      t        j                  d|¬«      fS t        |j                  |d¬«      }||   }t        ||t        «      }t        |d	| j                  ¬
«      }||d d …df   |d d …df   f   }|||fS )Nr   )Úmin_distancer   )r   r   ©Údtype)r   r   ©ÚdistanceÚk)Úmethodr:   )r7   r	   r#   r$   r   ÚlenÚnpÚzerosr   Úshaper
   Ú
OFAST_MASKr   r%   )	r+   Úoctave_imager7   Úfast_responser&   Úmaskr)   Úharris_responser(   s	            r,   Ú_detect_octavezORB._detect_octave•   sÜ   € Ø×"Ñ"ˆä# L°$·+±+¸t×?RÑ?RÓSˆÜ  ¸QÔ?ˆ	äˆy‹>˜QÒä—‘˜ uÔ-Ü—‘˜ UÔ+Ü—‘˜ UÔ+ðð ô & l×&8Ñ&8¸)ÈbÔQˆØ˜d‘Oˆ	ä*¨<¸ÄJÓOˆä'¨¸SÀDÇMÁMÔRˆØ# Iªa°¨d¡O°YºqÀ!¸t±_Ð$DÑEˆ	à˜,¨	Ð1Ð1r.   c                 óî  — t        |d«       | j                  |«      }g }g }g }g }t        t        |«      «      D ]á  }t	        j
                  ||   «      }t	        j                  |«      j                  dk  r n¥| j                  |«      \  }	}
}|j                  |	| j                  |z  z  «       |j                  |
«       |j                  t	        j                  |	j                  d   | j                  |z  |j                  ¬«      «       |j                  |«       Œã t	        j                  |«      }	t	        j                  |«      }
t	        j                  |«      }t	        j                  |«      }|	j                  d   | j                   k  r|	| _        || _        |
| _        || _        y|j+                  «       ddd…   d| j                    }|	|   | _        ||   | _        |
|   | _        ||   | _        y)z¥Detect oriented FAST keypoints along with the corresponding scale.

        Parameters
        ----------
        image : 2D array
            Input image.

        r   r   r6   Néÿÿÿÿ)r   r3   Úranger<   r=   ÚascontiguousarrayÚsqueezeÚndimrE   Úappendr    Úfullr?   r7   ÚvstackÚhstackr"   r&   r'   r)   r(   Úargsort)r+   r2   ÚpyramidÚkeypoints_listÚorientations_listÚscales_listÚresponses_listÚoctaverA   r&   r)   r(   r'   Úbest_indicess                 r,   Údetectz
ORB.detect¬   sÇ  € ô 	�˜Ôà×%Ñ% eÓ,ˆàˆØÐØˆØˆäœC ›LÖ)ˆFÜ×/Ñ/°¸±Ó@ˆLä�z‰z˜,Ó'×,Ñ,¨qÒ0áà15×1DÑ1DÀ\Ó1RÑ.ˆI�| Yà×!Ñ! )¨d¯n©n¸fÑ.DÑ"DÔEØ×$Ñ$ \Ô2Ø×ÑÜ—‘Ø—O‘O AÑ&Ø—N‘N FÑ*Ø&×,Ñ,ôôð ×!Ñ! )Õ,ð% *ô( —I‘I˜nÓ-ˆ	Ü—y‘yÐ!2Ó3ˆÜ—‘˜;Ó'ˆÜ—I‘I˜nÓ-ˆ	à�?‰?˜1Ñ × 0Ñ 0Ò0Ø&ˆDŒNØ ˆDŒKØ ,ˆDÔØ&ˆD�Nð %×,Ñ,Ó.©t°¨tÑ4Ð5G°t×7GÑ7GÐHˆLØ& |Ñ4ˆDŒNØ  Ñ.ˆDŒKØ ,¨\Ñ :ˆDÔØ& |Ñ4ˆD�Nr.   c                 óæ   — t        |j                  |d¬«      }t        j                  ||   t        j                  dt
        ¬«      }t        j                  ||   dd¬«      }t        |||«      }||fS )Né   r8   ÚC)r7   ÚorderÚcopyF)r\   r]   )r   r?   r=   ÚarrayÚintpr   r   )r+   rA   r&   r)   rC   r*   s         r,   Ú_extract_octavezORB._extract_octaveä   sh   € Ü% l×&8Ñ&8¸)ÈbÔQˆÜ—H‘HØ�d‰O¤2§7¡7°#Ô<Mô
ˆ	ô —x‘x ¨TÑ 2¸#ÀEÔJˆä ¨i¸ÓFˆà˜DÐ Ð r.   c                 ó¾  — t        |d«       | j                  |«      }g }g }t        j                  |«      t        j                  | j                  «      z  j                  t        j                  «      }t        t        |«      «      D ]Œ  }	||	k(  }
t        j                  |
«      dkD  sŒ!t        j                  ||	   «      }||
   }|| j                  |	z  z  }||
   }| j                  |||«      \  }}|j                  |«       |j                  |«       ŒŽ t        j                  |«      j                  t        «      | _        t        j"                  |«      | _        y)a  Extract rBRIEF binary descriptors for given keypoints in image.

        Note that the keypoints must be extracted using the same `downscale`
        and `n_scales` parameters. Additionally, if you want to extract both
        keypoints and descriptors you should use the faster
        `detect_and_extract`.

        Parameters
        ----------
        image : 2D array
            Input image.
        keypoints : (N, 2) array
            Keypoint coordinates as ``(row, col)``.
        scales : (N,) array
            Corresponding scales.
        orientations : (N,) array
            Corresponding orientations in radians.

        r   r   N)r   r3   r=   Úlogr    Úastyper_   rH   r<   ÚsumrI   r`   rL   rN   ÚviewÚboolr*   rO   Úmask_)r+   r2   r&   r'   r)   rQ   Údescriptors_listÚ	mask_listÚoctavesrV   Úoctave_maskrA   Úoctave_keypointsÚoctave_orientationsr*   rC   s                   r,   ÚextractzORB.extractï   s0  € ô( 	�˜Ôà×%Ñ% eÓ,ˆàÐØˆ	ô —6‘6˜&“>¤B§F¡F¨4¯>©>Ó$:Ñ:×BÑBÄ2Ç7Á7ÓKˆäœC ›LÖ)ˆFà! VÑ+ˆKä�v‰v�kÓ" QÓ&Ü!×3Ñ3°G¸F±OÓD�à#,¨[Ñ#9Ð Ø  D§N¡N°FÑ$:Ñ:Ð Ø&2°;Ñ&?Ð#à$(×$8Ñ$8Ø Ð"2Ð4Gó%Ñ!�˜Tð !×'Ñ'¨Ô4Ø× Ñ  Õ&ð! *ô$ Ÿ9™9Ð%5Ó6×;Ñ;¼DÓAˆÔÜ—Y‘Y˜yÓ)ˆ�
r.   c                 óÂ  — t        |d«       | j                  |«      }g }g }g }g }g }t        t        |«      «      D �]v  }t	        j
                  ||   «      }	t	        j                  |	«      j                  dk  r �n9| j                  |	«      \  }
}}t        |
«      dk(  rM|j                  |
«       |j                  |«       |j                  t	        j                  dt        ¬«      «       Œ±| j                  |	|
|«      \  }}|
|   | j                  |z  z  }|j                  |«       |j                  ||   «       |j                  ||   «       |j                  | j                  |z  t	        j                  |j                  d   t        j                   ¬«      z  «       |j                  |«       �Œy t        |«      dk(  rt#        d«      ‚t	        j$                  |«      }
t	        j&                  |«      }t	        j&                  |«      }t	        j&                  |«      }t	        j$                  |«      j)                  t        «      }|
j                  d   | j*                  k  r$|
| _        || _        || _        || _        || _        y|j7                  «       ddd…   d| j*                   }|
|   | _        ||   | _        ||   | _        ||   | _        ||   | _        y)zûDetect oriented FAST keypoints and extract rBRIEF descriptors.

        Note that this is faster than first calling `detect` and then
        `extract`.

        Parameters
        ----------
        image : 2D array
            Input image.

        r   r   )r   é   r6   znORB found no features. Try passing in an image containing greater intensity contrasts between adjacent pixels.NrG   )r   r3   rH   r<   r=   rI   rJ   rK   rE   rL   r>   rf   r`   r    Úonesr?   r_   ÚRuntimeErrorrN   rO   re   r"   r&   r'   r)   r(   r*   rP   )r+   r2   rQ   rR   rU   rT   rS   rh   rV   rA   r&   r)   r(   r*   rC   Úscaled_keypointsr'   rW   s                     r,   Údetect_and_extractzORB.detect_and_extract"  s¥  € ô 	�˜Ôà×%Ñ% eÓ,ˆàˆØˆØˆØÐØÐäœC ›L×)ˆFÜ×/Ñ/°¸±Ó@ˆLä�z‰z˜,Ó'×,Ñ,¨qÒ0âà15×1DÑ1DÀ\Ó1RÑ.ˆI�| Yä�9‹~ Ò"Ø×%Ñ% iÔ0Ø×%Ñ% iÔ0Ø ×'Ñ'¬¯©°ÄÔ(FÔGØà $× 4Ñ 4Ø˜i¨ó!ÑˆK˜ð  )¨™°·±ÀÑ1GÑGÐØ×!Ñ!Ð"2Ô3Ø×!Ñ! )¨D¡/Ô2Ø×$Ñ$ \°$Ñ%7Ô8Ø×ÑØ—‘ Ñ&Ü—'‘'Ð*×0Ñ0°Ñ3¼2¿7¹7ÔCñDôð ×#Ñ# KÖ0ð7 *ô: ˆ{Ó˜qÒ ÜðGóð ô
 —I‘I˜nÓ-ˆ	Ü—I‘I˜nÓ-ˆ	Ü—‘˜;Ó'ˆÜ—y‘yÐ!2Ó3ˆÜ—i‘iÐ 0Ó1×6Ñ6´tÓ<ˆà�?‰?˜1Ñ × 0Ñ 0Ò0Ø&ˆDŒNØ ˆDŒKØ ,ˆDÔØ&ˆDŒNØ*ˆDÕð %×,Ñ,Ó.©t°¨tÑ4Ð5G°t×7GÑ7GÐHˆLØ& |Ñ4ˆDŒNØ  Ñ.ˆDŒKØ ,¨\Ñ :ˆDÔØ& |Ñ4ˆDŒNØ*¨<Ñ8ˆDÕr.   N)g333333ó?r   iô  r   g{®Gáz´?g{®Gáz¤?)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r-   r3   rE   rX   r`   rn   rt   © r.   r,   r   r      sC   „ ñ[ð~ ØØØØØó ò,
ò2ò.65òp	!ò1*ófL9r.   r   )Únumpyr=   Úfeature.utilr   r   r   r   Úcornerr	   r
   r   r   Ú	transformr   Ú_shared.utilsr   Ú_shared.compatr   Úorb_cyr   r>   r@   Ú
OFAST_UMAXrH   ÚiÚabsÚjr   ry   r.   r,   Ú<module>r…      s¡   ðÛ ÷ó ÷ RÓ QÝ (Ý $Ý .å ð ˆR�X‰X�hÓ€
ÚI€
Ù	ˆs�BŽ€AÙ�J™s 1›vÑ&Ð&¨
±3°q³6Ñ(:¸QÑ(>Ö?ˆØ%&ˆ
�2˜‘6˜2 ™6�>Ò"ñ @ð 
ô
U9ˆ/Ð.õ U9r.   