Ë
    ðì�i¢  ã                   ó>   — d Z ddlZddlZddlmZ ddlmZ dd„Zd„ Zy)z¿
PassportEye::Util: Interface between SKImage and the PyTesseract OCR
NB: You must have the "tesseract" tool present in your path for this to work.

Author: Konstantin Tretyakov
License: MIT
é    N)Úimwrite)Úpytesseractc                 ó´  — | �| j                   d   dk(  rydt        «       z  }dt        «       z  }d|z  }	 t        | j                  «      j	                  d«      r‹t        j                  | «      dk\  rst        j                  | «      d	k  r[| j                  t
        j                  «      t        j                  d
d«      d	z
  z  dz   } | j                  t
        j                  «      } t        || «       |rdj                  |«      }ndj                  |«      }t        j                  ||dd|¬«       t!        |d¬«      }	 |j#                  «       j%                  «       |j'                  «        t        j(                  |«       t        j(                  |«       S # |j'                  «        w xY w# t        j(                  |«       t        j(                  |«       w xY w)a  Runs Tesseract on a given image. Writes an intermediate tempfile and then runs the tesseract command on the image.

    This is a simplified modification of image_to_string from PyTesseract, which is adapted to SKImage rather than PIL.

    In principle we could have reimplemented it just as well - there are some apparent bugs in PyTesseract, but it works so far :)

    :param mrz_mode: when this is True (default) the tesseract is configured to recognize MRZs rather than arbitrary texts.
                     When False, no specific configuration parameters are passed (and you are free to provide your own via `extra_cmdline_params`)
    :param extra_cmdline_params: extra parameters passed to tesseract. When mrz_mode=True, these are appended to whatever is the
                    "best known" configuration at the moment.
                    "--oem 0" is the parameter you might want to pass. This selects the Tesseract's "legacy" OCR engine, which often seems
                    to work better than the new LSTM-based one.
    Néÿÿÿÿr   Ú z%s.bmpz%sz%s.txtÚfloaté   g       @é   gAíþÿÿß?zv--psm 6 -c tessedit_char_whitelist=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789>< -c load_system_dawg=F -c load_freq_dawg=F {}z{}Útxt)ÚlangÚconfigzutf-8)Úencoding)ÚshapeÚ_tempnamÚstrÚdtypeÚ
startswithÚnpÚnanminÚnanmaxÚastypeÚfloat64ÚpowerÚuint8r   Úformatr   Úrun_tesseractÚopenÚreadÚstripÚcloseÚcleanup)ÚimgÚmrz_modeÚextra_cmdline_paramsÚinput_file_nameÚoutput_file_name_baseÚoutput_file_namer   Úfs           úy/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/passporteye/util/ocr.pyÚocrr*      s~  € ð €{�c—i‘i ‘m qÒ(ØØ¤£Ñ+€OØ ¤8£:Ñ-ÐØÐ"7Ñ7Ðð.äˆs�y‰y‹>×$Ñ$ WÔ-´"·)±)¸C³.ÀAÒ2EÌ"Ï)É)ÐTWË.Ð\]ÒJ]Ø—*‘*œRŸZ™ZÓ(¬B¯H©H°S¸!Ó,<¸qÑ,@ÑAÀKÑOˆCØ—*‘*œRŸX™XÓ&ˆCÜ� Ô%áðFßGMÁvÐNbÓGcñ ð —[‘[Ð!5Ó6ˆFä×!Ñ! /Ø"7Ø"'Ø'+Ø)/õ		1ô Ð!¨GÔ4ˆð	Ø—6‘6“8—>‘>Ó#à�G‰GŒIä×Ñ˜OÔ,Ü×ÑÐ,Õ-øð �G‰G�Iûä×Ñ˜OÔ,Ü×ÑÐ,Õ-ús$   ¶DF+ Ä>F ÅF+ ÆF(Æ(F+ Æ+,Gc                  óF   — t        j                  d¬«      } | j                  S )z1TODO: Use the with(..) version for auto-deletion?Útess_)Úprefix)ÚtempfileÚNamedTemporaryFileÚname)Útmpfiles    r)   r   r   A   s   € ä×)Ñ)°Ô9€GØ�<‰<Ðó    )Tr   )	Ú__doc__r.   Únumpyr   Úimageior   r   r*   r   © r2   r)   ú<module>r7      s#   ðñó Û Ý Ý #ó/.ódr2   