+
    œ°³jw   ã                   ó:  € R t ^ RIt^ RIt^RIHt ^RIHt ^RIH	t	H
t
HtHt ^RIHtHtHtHtHt ^RIHtHt ^RIHtHtHtHtHt ]! 4       '       d   ^ RIt^ RIHt ]P@                  ! ]!4      t"R	 t#RR
 R llt$ ! R R]RR7      t%] ! R R]4      4       t&R.t'R# )z%Image processor class for LayoutLMv3.N)ÚTorchvisionBackend)ÚBatchFeature)ÚChannelDimensionÚgroup_images_by_shapeÚreorder_imagesÚto_pil_image)ÚIMAGENET_STANDARD_MEANÚIMAGENET_STANDARD_STDÚ
ImageInputÚPILImageResamplingÚSizeDict)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringÚis_pytesseract_availableÚloggingÚrequires_backends)Ú
functionalc                 óþ   € \        R V ^ ,          V,          ,          4      \        R V ^,          V,          ,          4      \        R V ^,          V,          ,          4      \        R V ^,          V,          ,          4      .# )iè  )Úint)ÚboxÚwidthÚheights   &&&Ú{/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/layoutlmv3/image_processing_layoutlmv3.pyÚnormalize_boxr   0   s`   € äˆD�C˜•F˜U•NÕ#Ó$ÜˆD�C˜•F˜V•OÕ$Ó%ÜˆD�C˜•F˜U•NÕ#Ó$ÜˆD�C˜•F˜V•OÕ$Ó%ð	ð ó    c          	      ó€   € V ^8„  d   QhRRR\         R,          R\         R,          R\         \        ,          R,          /# )é   Úimageznp.ndarray | torch.TensorÚlangNÚtesseract_configÚinput_data_format)Ústrr   )Úformats   "r   Ú__annotate__r%   9   sC   € ÷ ,#ñ ,#Ø&ð,#ä
��*ð,#ô ˜D•jð,#ô Ô-Õ-°Õ4ñ	,#r   c                ó  € \        \        R.4       \        V R4      '       d    V P                  4       P	                  4       p M6\        V \        P                  4      '       g   \        P                  ! V 4      p Ve   TMRp\        WR7      pVP                  w  rV\        P                  ! WARVR7      pVR,          VR,          VR	,          VR
,          VR,          3w  r‰r«p\        V4       UUu. uF  w  rÞVP                  4       '       d   K  VNK!  	  ppp\        V4       UUu. uF  w  rÞWß9  g   K  VNK  	  ppp\        V	4       UUu. uF  w  ppWß9  g   K  VNK  	  p	pp\        V
4       UUu. uF  w  ppWß9  g   K  VNK  	  p
pp\        V4       UUu. uF  w  ppWß9  g   K  VNK  	  ppp\        V4       UUu. uF  w  ppWß9  g   K  VNK  	  ppp. p\        WšW¼4       F-  w  ppppVVVV,           VV,           .pVP!                  V4       K/  	  . pV F  pVP!                  \#        VWV4      4       K   	  \%        V4      \%        V4      8X  g   Q R4       hVV3# u uppi u uppi u uppi u uppi u uppi u uppi )zdApplies Tesseract OCR on a document image, and returns recognized words + normalized bounding boxes.ÚpytesseractÚcpuÚ ©r"   Údict)r    Úoutput_typeÚconfigÚtextÚleftÚtopr   r   z-Not as many words as there are bounding boxes)r   Úapply_tesseractÚhasattrr(   ÚnumpyÚ
isinstanceÚnpÚndarrayÚarrayr   Úsizer'   Úimage_to_dataÚ	enumerateÚstripÚzipÚappendr   Úlen)r   r    r!   r"   Ú	pil_imageÚimage_widthÚimage_heightÚdataÚwordsr/   r0   r   r   ÚidxÚwordÚirrelevant_indicesÚcoordÚactual_boxesÚxÚyÚwÚhÚ
actual_boxÚnormalized_boxesr   s   &&&&                     r   r1   r1   9   sG  € ô ”o¨ Ô7ô ˆu�e×ÒØ—	‘	“×!Ñ!Ó#‰Ü˜œrŸz™z×*Ò*Ü—’˜“ˆà+;Ò+GÑ'ÈRÐô ˜UÔH€IØ )§¡Ñ€KÜ×$Ò$ YÀvÐVfÔg€DØ&*¨6¥l°D¸µLÀ$ÀuÅ+ÈtÐT[Í}Ð^bÐckÕ^lÐ&lÑ#€E�˜Vô 09¸Ô/?ÔTÑ/?¡) #ÀtÇzÁzÇ|Ÿ#˜#Ñ/?ÐÑTÜ#,¨UÔ#3ÔUÑ#3‘i�c°sÑ7T�TˆTÑ#3€EÑUÜ$-¨d¤OÔU¡O‘j�c˜5°sÑ7T�EˆE¡O€DÑUÜ#,¨S¤>Ô
S¡>‘Z�S˜%°SÑ5R�5ˆ5¡>€CÑ
SÜ%.¨uÔ%5ÔWÑ%5‘z�s˜E¸Ñ9V�UˆUÑ%5€EÑWÜ&/°Ô&7ÔYÑ&7™
˜˜U¸3Ñ;X�eˆeÑ&7€FÑYð €LÜ˜$ UÖ3‰
ˆˆ1ˆa�Ø˜˜A �E 1 q¥5Ð)ˆ
Ø×Ñ˜JÖ'ñ 4ð
 ÐÛˆØ×Ñ¤¨c°;Ó MÖNñ ô ˆu‹:œÐ-Ó.Ô.Ð_Ð0_Ó_Ð.àÐ"Ð"Ð"ùó) UùÛUùÛUùÛ
SùÛWùÛYsH   Ã0I#ÄI#Ä&
I)Ä5I)ÅI/ÅI/Å3I5ÆI5ÆI;Æ*I;ÇJÇJc                   ó0   a € ] tR t^ht o RtV 3R ltRtV tR# )ÚLayoutLMv3ImageProcessorKwargsaÅ  
apply_ocr (`bool`, *optional*, defaults to `True`):
    Whether to apply the Tesseract OCR engine to get words + normalized bounding boxes. Can be overridden by
    the `apply_ocr` parameter in the `preprocess` method.
ocr_lang (`str`, *optional*):
    The language, specified by its ISO code, to be used by the Tesseract OCR engine. By default, English is
    used. Can be overridden by the `ocr_lang` parameter in the `preprocess` method.
tesseract_config (`str`, *optional*):
    Any additional custom configuration flags that are forwarded to the `config` parameter when calling
    Tesseract. For example: '--psm 6'. Can be overridden by the `tesseract_config` parameter in the
    `preprocess` method.
c                óZ   <€ V ^8„  d   Qh/ S[ ;R&   S[R,          ;R&   S[R,          ;R&   # )r   Ú	apply_ocrNÚocr_langr!   )Úboolr#   )r$   Ú__classdict__s   "€r   r%   Ú+LayoutLMv3ImageProcessorKwargs.__annotate__h   s3   ø‡ ‚ ñ �Oñ ñ �D�jÑñ ñ  ˜D•jÑ ò! r   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)rU   s   @r   rP   rP   h   s   ø‡ € ñ÷ ƒ r   rP   F)Útotalc                   ó¾   a a€ ] tR t^{t o]t]P                  t]	t
]tR^àR^à/tRtRtRtRtRtRtV3R lV 3R llt]V3R lV 3R	 ll4       tRV3R
 lR lltRtVtV ;t# )ÚLayoutLMv3ImageProcessorr   r   TNr)   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# )r   Úkwargs)r   rP   )r$   rU   s   "€r   r%   Ú%LayoutLMv3ImageProcessor.__annotate__‰   s   ø€ ÷ #ñ #¡Ñ(FÕ!Gñ #r   c                ó(   <€ \         SV `  ! R/ VB  R # )NrW   )ÚsuperÚ__init__)Úselfrd   Ú	__class__s   &,€r   rh   Ú!LayoutLMv3ImageProcessor.__init__‰   s   ø€ Ü‰ÒÑ"˜6Ô"r   c                ó<   <€ V ^8„  d   QhRS[ RS[S[,          RS[/# )r   Úimagesrd   Úreturn)r
   r   rP   r   )r$   rU   s   "€r   r%   re   �   s)   ø€ ÷ 4ñ 4¡ð 4±vÑ>\Õ7]ð 4Ñbnñ 4r   c                ó&   <€ \         SV `  ! V3/ VB # )N)rg   Ú
preprocess)ri   rm   rd   rj   s   &&,€r   rp   Ú#LayoutLMv3ImageProcessor.preprocessŒ   s   ø€ ä‰wÒ! &Ñ3¨FÑ3Ð3r   c          "      ó0  <€ V ^8„  d   QhRS[ R,          RS[RS[RRRS[RS[R	S[R
S[RS[RS[S[ S[,          ,          R,          RS[S[ S[,          ,          R,          RS[R,          RS[S[,          R,          RS[RS[R,          RS[R,          RS[/# )r   rm   ztorch.TensorÚ	do_resizer8   Úresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanNÚ	image_stdÚdisable_groupingÚreturn_tensorsrR   rS   r!   rn   )ÚlistrT   r   Úfloatr#   r   r   )r$   rU   s   "€r   r%   re   �   s   ø€ ÷ Bñ Bá�^Õ$ðBñ ðBñ ð	Bð
 LðBñ ðBñ ðBñ ðBñ ðBñ ðBñ ™D¡�KÕ'¨$Õ.ðBñ ™4¡�;Õ&¨Õ-ðBñ  �+ðBñ ™jÕ(¨4Õ/ðBñ ðBñ  ˜•*ð!Bñ"  �*ð#Bñ& 
ñ'Br   c           	     óü  € V'       d‘   \        V R 4       . p. pV Fz  pVP                  '       d   \        P                  R4       \	        VP                  4       VV\        P                  R7      w  ppVP                  V4       VP                  V4       K|  	  \        WR7      w  pp/ pVP                  4        F&  w  ppV'       d   V P                  VW4R7      pVVV&   K(  	  \        VV4      p\        VVR7      w  pp/ pVP                  4        F9  w  ppV'       d   V P                  VV4      pV P                  VWxWšV4      pVVV&   K;  	  \        VV4      p\        RV/VR7      pV'       d   XVR&   XVR&   V# )	r'   z]apply_ocr can only be performed on cpu. Tensors will be transferred to cpu before processing.r*   )r|   )r   r8   rt   Úpixel_values)rB   Útensor_typerC   Úboxes)r   Úis_cudaÚloggerÚwarning_oncer1   r(   r   ÚFIRSTr=   r   ÚitemsÚresizer   Úcenter_cropÚrescale_and_normalizer   ) ri   rm   rs   r8   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   rR   rS   r!   rd   Úwords_batchÚboxes_batchr   rC   rƒ   Úgrouped_imagesÚgrouped_images_indexÚresized_images_groupedÚshapeÚstacked_imagesÚresized_imagesÚprocessed_images_groupedÚprocessed_imagesrB   s    &&&&&&&&&&&&&&&&&,              r   Ú_preprocessÚ$LayoutLMv3ImageProcessor._preprocess�   s“  € ÷* Ü˜d MÔ2ØˆKØˆKÛ�Ø—=—=�=Ü×'Ñ'Øwôô  /Ø—I‘I“K Ð+;ÔO_×OeÑOeô ‘��uð ×"Ñ" 5Ô)Ø×"Ñ" 5Ö)ñ  ô 0EÀVÔ/oÑ,ˆÐ,Ø!#ÐØ%3×%9Ñ%9Ö%;Ñ!ˆE�>ßØ!%§¡°>È Ó!`�Ø,:Ð" 5Ó)ñ &<ô (Ð(>Ð@TÓUˆô 0EÀ^ÐfvÔ/wÑ,ˆÐ,Ø#%Ð Ø%3×%9Ñ%9Ö%;Ñ!ˆE�>ßØ!%×!1Ñ!1°.À)Ó!L�à!×7Ñ7Ø 
¸LÐV_óˆNð /=Ð$ UÓ+ñ &<ô *Ð*BÐDXÓYÐä .Ð2BÐ!CÐQ_Ô`ˆçØ'ˆD�‰MØ'ˆD�‰Màˆr   rW   )TNN)rX   rY   rZ   r[   rP   Úvalid_kwargsr   ÚBILINEARrt   r   rz   r	   r{   r8   rs   rw   ry   rR   rS   r!   rh   r   rp   r–   r^   r_   Ú__classcell__)rj   rU   s   @@r   rb   rb   {   s�   ù‡ € à1€LØ!×*Ñ*€HØ'€JØ%€IØ�c˜7 CÐ(€DØ€IØ€JØ€LØ€IØ€HØÐ÷#ó #ð ÷4ò 4ó ð4÷B÷ Bò Br   rb   )NN)(r\   r3   r5   ÚtorchÚimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr   r   r   r   Úimage_utilsr   r	   r
   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   r   r   r'   Útorchvision.transforms.v2r   ÚtvFÚ
get_loggerrX   r…   r   r1   rP   rb   Ú__all__rW   r   r   Ú<module>r¦      s›   ðñ ,ã Û å ;Ý 2ß eÓ e÷õ ÷ 5÷õ ñ ×ÒÛå 7ð 
×	Ò	˜HÓ	%€ò÷,#ô^! \¸õ !ð& ôVÐ1ó Vó ðVðr &Ð
&‚r   