%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/hplip/base/__pycache__/
Upload File :
Create Path :
Current File : //usr/share/hplip/base/__pycache__/imageprocessing.cpython-312.pyc

�

=	f���v�ddlmZmZddl�ddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZdZ
dZdZd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d4d�Z"d�Z#d�Z$d�Z%d�Z&d �Z'd!�Z(d"�Z)d#�Z*d$�Z+d%�Z,d&�Z-d'�Z.d(�Z/d)�Z0d*�Z1d+�Z2d,�Z3d-�Z4d.�Z5d/�Z6d0�Z7d1�Z8d2�Z9d3�Z:y)5�)�utils�os_utils)�*N)�core_install)�dcheck���2�c	�8�ddl}ddl}	|jd|jdf}t|j	|�dz�}|j|j
||d�gd�g�}|j|dd�dd�f�}|ddz}|ddz}	|j	||	g�|zjd|j	||	g�|zjd|j	||	g�|zjd|j	||	g�|zjdg}
|
D�cgc]}|d��	}}|D�
cgc]
}
|
dkDs�	|
��}}
|D�
cgc]
}
|
dks�	|
��}}
|
D�cgc]}|d��	}}|D�cgc]
}|dkDs�	|��}}|D�cgc]
}|dks�	|��}}t|�}t|�}t|�}t|�}tt||z
��}tt||z
��}|jddt|dz|z
�gddt|dz|	z
�ggd�g�}|j|�|j|�zdd�dd�f}|j||||f|j��}|Scc}wcc}
wcc}
wcc}wcc}wcc}w)Nr����?)rrr��?)�flags)�numpy�cv2�shape�tuple�array�vstack�getRotationMatrix2D�matrix�A�max�min�int�abs�
warpAffine�INTER_LINEAR)�image�angle�npr�
image_size�image_center�rot_mat�rot_mat_notranslate�image_w2�image_h2�rotated_coords�pt�x_coords�x�x_pos�x_neg�y_coords�y�y_pos�y_neg�right_bound�
left_bound�	top_bound�	bot_bound�new_w�new_h�	trans_mat�
affine_mat�results                             �(/usr/share/hplip/base/imageprocessing.py�rotate_imager=4s�������+�+�a�.�%�+�+�a�.�1�J�����*�-��1�2�L��i�i�	�	 �	 ��u�c�	:�I�F��G��)�)�G�A�a�C��1��H�$5�6���!�}�s�"�H��!�}�s�"�H�
���H�9�x�(�	)�,?�	?�B�B�1�E�	���H�x�(�	)�,?�	?�B�B�1�E�	���H�9�x�i�(�	)�,?�	?�B�B�1�E�	���H�x�i�(�	)�,?�	?�B�B�1�E�	�N�!/�/�"��1��/�H�/� �*�1�A��E�Q�*�E�*� �*�1�A��E�Q�*�E�*� .�/�"��1��/�H�/� �*�1�A��E�Q�*�E�*� �*�1�A��E�Q�*�E�*��e�*�K��U��J��E�
�I��E�
�I���K�*�,�-�.�E���I�	�)�*�+�E��	�	�	
�A�s�5�3�;��)�*�+�	
�A�s�5�3�;��)�*�+����I��)�)�I�&����7�);�;�Q�q�S�!�V�D�J��^�^�
��	������	��F��M��E0��*��*��/��*��*s<�'I>�9
J�J�
J�J�#J
�5
J�J�

J�Jc��ttj|tjdzz��dz}|dzdk(r|ntj|z
}|tjztjztjz}|tj|�z|tj
|�zz}|tj
|�z|tj|�zz}||krtj||�ntj||�}tj|z
|z
}	||kr|n|}
|
tj|�z}|tj
|�ztj
|	�z}|tj|�z}
|
tj|�z}|d|zz
|d|
zz
fS)a9
    Given a rectangle of size wxh that has been rotated by 'angle' (in
    radians), computes the width and height of the largest possible
    axis-aligned rectangle within the rotated rectangle.

    Original JS code by 'Andri' and Magnus Hoff from Stack Overflow

    Converted to Python by Aaron Snoswell
    r
�rr)r�math�floor�pi�cos�sin�atan2�tan)�w�hr!�quadrant�
sign_alpha�alpha�bb_w�bb_h�gamma�delta�length�d�ar0r,s               r<�largest_rotated_rectrS{sd���4�:�:�e�t�w�w��{�3�4�5��9�H�$�q�L�Q�.��T�W�W�u�_�J�
�$�'�'�
!�D�G�G�
+�t�w�w�6�E��t�x�x�����T�X�X�e�_�!4�4�D��t�x�x�����T�X�X�e�_�!4�4�D�'(�1�u�D�J�J�t�T�"�4�:�:�d�D�3I�E��G�G�e�O�e�#�E��q�5�Q�q�F�����%�� �A�	�D�H�H�U�O��d�h�h�u�o�-�A�	�D�H�H�U�O��A�	�D�H�H�U�O��A�	
�q�1�u���q�1�u����c�l�|jd|jdf}t|ddz�t|ddz�f}||dkDr|d}||dkDr|d}t|d|dzz
�}t|d|dzz�}t|d|dzz
�}t|d|dzz�}|||�||�fS)zn
    Given a NumPy / OpenCV 2 image, crops it to the given width and height,
    around it's centre point
    rrr)rr)	r �width�heightr#r$�x1�x2�y1�y2s	         r<�crop_around_centerr\�s����+�+�a�.�%�+�+�a�.�1�J��
�1�
��+�,�c�*�Q�-�#�2E�.F�G�L��z�!�}���1�
��
�
�1�
���A���	�\�!�_�u�s�{�
*�	+�B�	�\�!�_�u�s�{�
*�	+�B�	�\�!�_�v��|�
+�	,�B�	�\�!�_�v��|�
+�	,�B���B���2����rTc�b�ddl}ddl}ddlm}ddl}|j|�}|jdd\}}|j||j�}|j|ddd��}	|j|	d|jdzddd	�
�}
g}g}|
dD]c\}
}}}|j|j||z
||
z
��}|j|�t|�}|dk7s�S|j|��e|sd}|St!|�}|D]}|t|�k(s�|}�|dk\s|dkrd}|S)
Nr��Imager
�dr?)�apertureSizerg�f@�)�
minLineLength�
maxLineGap���)rr�PILr_r@rr�cvtColor�COLOR_BGR2GRAY�Canny�HoughLinesPrB�degreesrE�appendrr)�imgr"rr_r@r �image_height�image_width�gray�edges�lines�angles�temp_anglesrXrZrYr[r!�median_angle�items                    r<�
Deskew_angle1rx�sH������
�(�(�3�-�E� %���A�a� 0��L�+��<�<��s�1�1�2�D��I�I�d�C��1�I�5�E��O�O�E�1�d�g�g��o�s�#�Z[�O�\�E�
�F��K���(�!���B��B�����Z�T�Z�Z��R���b��9�:�����5�!��E�
���A�:��M�M�%� �!�������6�{��� ���3�t�9�$��L� �	���l�c�1����rTc����ddl}ddl}ddl�ddlm}ddlm�|j\}}�j|jd�j��j�}d|j||f�dzz
}��fd�}d}	d}
�j|
|
|	z|	�}g}|D]}
|||
�\}}|j|��!|sd}|St|�}||j!|�}|dkr|}n|}|d	k\s|d
krd}|S)Nrr^��
interpolation�1r��o@c����j||dd��}�j|d��}�j|dd|ddz
dz�}||fS)NFr)�reshape�orderr��axis���r
)�rotate�sum)�arrr!�data�hist�score�interr"s     ��r<�
find_scorez!Deskew_angle2.<locals>.find_score�sY����|�|�C���Q�|�?���v�v�d��v�#������Q�R��4���9�,��2�3���U�{�rTrbrerf)�sysr@rrgr_�
scipy.ndimager{�sizer�convert�getdata�uint8r�arangermr�index)rnr�r@�im�wd�ht�pix�bin_imgr�rO�limitrt�scoresr!r�r��
best_angle�
best_scorer�r"s                  @@r<�
Deskew_angle2r��s�������4��X�X�F�B��
�(�(�3�;�;�s�#�+�+�-�r�x�x�
8�C��3�;�;��B�x�(�5�0�1�G�
�
�E�
�E�
�Y�Y��v�u�U�{�E�
2�F�
�F���� ��%�0���e��
�
�e�����
�����[�
�����Z�0�1�J��A�~��
��
��b��J�#�-��
��rTc
��ddl}ddl}ddlm}ddl}t|�}t
|�}|dkr|dkrt||g�}n
t||g�}|dk7r|dk7s|S|dk\s|dkr|S|j|�}|jdd\}	}
|j|�}t||�}t|gt|
|	|j|�����}
|j!|
�S)Nrr^�Zi����rerfr
)rrrgr_r@rxr�rrrr�copyr=r\rS�radians�	fromarray)r�r"rr_r@�angle1�angle2r!r rorp�
image_orig�
image_rotated�image_rotated_croppeds              r<�deskewr�s�������
�2�
�F�
�2�
�F�
��{�v��{��V�F�O�$���V�F�O�$���R�K�E�S�L��	�
���u��|��	��H�H�R�L�E� %���A�a� 0��L�+������J� ���.�M�.��
�
!�������U�#��
���?�?�0�1�1rTc��ddlm}	|j|�j}|r	|ddkry|ddkr|ddkr|ddkr|dk(ryy)Nr)�	ImageStati,Trr
F)rgr��Stat�var)r��lineart_moder��vs    r<�	blankpager�(sY���$����r����A��!�A�$��*���Q�4�#�:�a��d�S�j��1����<�RW�CW��rTc��ddl}ddl}|jdd\}}|dz|dz}}|j||f|d�}|j	|d�}	|j	|d�}
t||
z||	zz�}t||	z||
zz�}|dxx|dz|z
z
cc<|dxx|dz|z
z
cc<|j
||||f�S)Nrr
r)rr)rr)rr
)rr
)rrrrrrr)
r r!rr"rHrG�cX�cY�MrCrD�nW�nHs
             r<�rotate_boundr�5s������[�[��!�_�F�Q���A��q�1�u��R�
	����R��5�&�#�6�A�
�&�&��4��/�C�
�&�&��4��/�C�

�a�#�g�!�c�'�
"�	#�B�	�a�#�g�!�c�'�
"�	#�B��d�G��Q��"�}��G��d�G��Q��"�}��G��>�>�%��R��H�-�-rTc���tt��dk\r)ddl}|j|jd�ddlm}m}nddlm}m}||j��5}	|j|�|j�|j�}|j�\}}}}	|cddd�S#t$r%|jd�}|j|�Y�mwxYw#1swYyxYw)N�r�C)�
PyTessBaseAPI�PSM)�psm�RGB)r�get_tesseract_version�locale�	setlocale�LC_ALL�	tesserocrr�r��AUTO_OSD�SetImage�IOErrorr��	Recognize�
AnalyseLayout�Orientation)
r�r�r�r��api�it�orientation�	directionr��deskew_angles
          r<�orientangler�Os���
� �"�#�q�(���������,�0�0�0�	�3�<�<�	(�
�C�	��L�L���	�
�
��
�
�
�
 ��68�n�n�6F�3��Y��|��
�
���	����E�"�B��L�L���	��
�
�s0�C�B.�.6C�.+C�C�C�C�C(c��ddlm}ddl}ddddd�}t|j	|�||�}|j|�S)Nrr^i�r�)rrr
r?)rgr_rr�rr�)r�r!r_r"�orient_dict�rotateds      r<�
autoorientr�cs>�����3�#��,�K�����"��k�%�&8�9�G��O�O�G�$�$rTc�V�|j\}}|jdd|dz
|dz
f�S)N�)r��crop)rnrGrHs   r<�initialcropr�ms/���8�8�D�A�q��8�8�R��Q�r�T�1�R�4�(�)�)rTc���t|�D]P\}}|j�tt|dt��t|dt�z}|tks�N|cSS�N)�	enumerate�sort�floatr��obviousness�len�	threshold)�vals�i�tmp�averages    r<�	find_liner�qs]���4�����#����
���C���-�.�/��C���4E�0F�F���i���H�	�

�HrTc	�\�ddl}|j\}}dd||g}t|j��}g}|D]}|j	t|���t
j�}|jd�}	|	ddk\r5|jt|�D�
cgc]}
||
|z|
dz|z��c}
�}n4|jt|�D�
cgc]}
||
|z|
dz|z��c}
�}|j�}t|�|d<|j|�}|t|�z
|d<|j|dd�}
t|
�|d<|j|dd�}|j|�}|t|�z
|d<|d|dk\s|d|dk\ryt!|�Scc}
wcc}
w)Nr�.�3rr?r
)rr��listr�rmr�platform�python_version�splitr�range�xranger�r��flipud�swapaxesr)rnr"rVrW�retval�pixelsr��pixel�
pyPlatform�numr��forupper�forlower�forleft�forrights               r<�getboxr�zs�����H�H�M�E�6���%��
�F�
�#�+�+�-�
 �F�
�D�� �����C��J�� ��(�(�*�J�
�
�
�3�
�C�
�1�v��}��x�x�%��-�P�Q��a�%�i��Q��%��8�P�Q���x�x�&��.�Q�Q��a�%�i��Q��%��8�Q�R���y�y�{�H��(�#�F�1�I��y�y��"�H���8�,�,�F�1�I��k�k�(�1�Q�'�G��'�"�F�1�I��{�{�8�A�a�(�H��y�y��"�H��	�(�+�+�F�1�I�
�a�y�F�1�I�����f�Q�i�!7����=���5Q��Qs�F$�F)c��ddlm}ddl}ddl}|j	|j|�d�}t
|�}|j|dkD�}|jd��\}}|jd��\}	}
|j|�||	�||
�f}t|j|��}t|�}
|j|
�}|S)Nrr^�r?r?r�)rgr_rr�blurr�
auto_canny�argwhererrr�r�r�r�)r�r_r"r�blurred�canny�ptsrZrXr[rY�croppedrn�boxr;s               r<�autocropr�s�������h�h�r�x�x��|�U�+�G��w��E�
�+�+�e�A�g�
�C��G�G��G�O�E�B�r��G�G��G�O�E�B�r��h�h�r�l�2�b�5�"�R�%�<�(�G�
�e�o�o�g�.�
/�C�
��+�C�
�X�X�c�]�F��MrTc�X�ddlm}ddl}ddl}|j	|j|�d�}|j
|dd�}|j|dkD�}|jd��\}}|jd��\}	}
|j|�d|	�||
�f}|j|�S)Nrr^r��
rr�)rgr_rrr�rrjr�rrr�)r�r_r"rr�rrrZrXr[rYrs            r<�	mixedfeedr�s�������h�h�r�x�x��|�U�+�G��I�I�g�r�3�'�E�
�+�+�e�A�g�
�C��G�G��G�O�E�B�r��G�G��G�O�E�B�r��h�h�r�l�1�R�4��B��;�'�G��?�?�7�#�#rTc��	ddlm}m}|�}|D]}	|j||�d��	|j
|�|D]}tj|��|S#ddlm}ddlm}|�}Y�gxYw)Nr)�
PdfFileMerger�
PdfFileReader��	PdfMerger)�	PdfReader�hpscan)	�PyPDF2r	r
rr
rm�write�os�remove)�adf_page_files�
outputfiler	r
�merger�ps      r<�generatePdfFiler�s���!�7�����2��	�	�
�
�m�A�&��1�2��
�L�L���
���
�	�	�!������+!�5�5����s�A!�!A8c	�R�ddlm}ddlm}		|j	||dz|dzf�}
d}|D]�}|	j|�}
	|rW||dk(s||dk(rG|
j
||z
dz||z
dzf�|
j|
|dz|dz||z
dz||z
dz�nF|
j
||z
dz||z
dzf�|
j|
|dz|dz||z
dz||z
dz�|
j!�t#j$|�|dz
}��|
j'�|S#t$rtjd�Y�^t$r:}tj|�trtjd�Yd}~��d}~wt$r}tjd�Yd}~��d}~wwxYw)Nr)�canvasr^g�ׁsF��?rr?)�reportlab.pdfgenrrgr_�Canvas�open�setPageSize�drawInlineImage�	NameErrorr��exit�AssertionError�log�error�PY3�	Exception�showPager�unlink�save)rr�orient_list�brx�bry�tlx�tly�output_pathrr_�cr�rr��es               r<�generatePdfFile_canvasr1�s���'���&	�
�
�j�3�v�:�s�6�z�":�;�A��A�
����J�J�q�M�r���{�1�~��2�k�!�n��6I��}�}�s�3�w��.��S��&�0@�A�B�� � ��c�&�j�C��J�3�s�7�F�BR�WZ�[^�W^�`f�Vf�h��}�}�s�3�w��.��S��&�0@�A�B�� � ��c�&�j�C��J�3�s�7�F�BR�VY�Z]�V]�_e�Ue�g�	�z�z�|�	�y�y��|��!�t�q�7�<�F�F�H����-���8�8�A�;����9�9�Q�<���x�x��{������8�8�A�;�;���s+�BD�F&�>F&�0E;�;F&�F!�!F&c����ddl�ddlm}	ddlm}|dk(r|�}g}d}	|t
|�k�rT||||dzg}|D�cgc]}|j|���}	}t|	D�
cgc])}
�j|
j�|
jf��+c}
�dd��j��fd�|	D��}|j|�}|D]}tj|��	|dk(rZd}
|jd	�}|j!|
�j#t|
d
��d|
z}t%j&|�n(t%j(d||�}
|j!|
�|d
z}|t
|�kr��T|dk(r@t%j(d||�}t|d�5}j+|�ddd�	|Sy#ddlm}|dk(r|�}Y���xYwcc}wcc}
w#1swY	|SxYw)Nrr^)r	�.pdfrrc3�^�K�|]$}�j|j������&y�wr�)�asarray�resize)�.0rG�	min_shaper"s  ��r<�	<genexpr>z documentmerge.<locals>.<genexpr>Ls#�����Q�a��
�
�A�H�H�Y�,?� A�Q�s�*-ztemp.pdfr��rbzrm -f �	hpscandocr
�wb)rrgr_rr	rr�r�sortedr�r��hstackr�rrr�r(rmr�run�createSequencedFilenamer)r�extr.r_r	r�list_imr�r0�imgs�z�	imgs_combr�temp�cmd�output�foutr8r"s                 @@r<�
documentmergerJ$s������%�(��&�=�"�_�F��G�	�A�"�&�c�.�!�
!�!�!�$�n�Q�q�S�&9�:��*1�3�Q�5�:�:�a�=�3��3���E�1�b�f�f�Q�V�V�n�a�f�f�6�E�F�q�I�!�L�	��I�I�Q�4�Q�S�	��O�O�Y�/�	��	�A��I�I�a�L�	�	��&�=��D�!�)�)�%�0�I��N�N�D�"��M�M�$�t�D�/�*��T�/�C��I�I�c�N��0�0��c�;�O�D��N�N�D�"�
��E��?�c�.�!�
!�@�f�}��.�.�{�C��M��
�&�$�
�	�4��L�L���	�	!��
���I%�5��&�=�"�_�F��64��E�<	�	!��
�s#�G�G(�(.G-�0G2�G%�2G=c���ddl}ddl}|j|�}tt	dd|z
|z��}ttdd|z|z��}|j
|||�}|S)Nrr�)rr�medianrrrrj)r �sigmar"rr��lower�upper�edgeds        r<r�r�qse����
�	�	�%��A�
��A��e��q�(�)�*�E���C�#��+��)�*�+�E��I�I�e�U�E�*�E��LrTc��ddlm}ddl}|j|�j	�}d||dk<d||dk\<|j|�S)Nrr^r�rLr�)rgr_rr5r�r�)r�r_r"�bws    r<�crushedrT�sG����	���B��	�	�	�B��B�r�B�w�K��B�r�S�y�M��?�?�2��rTc�4�ddl}ddl}ddlm}|j	|�}|j||j�}d}d}||z|z}|j|dd�j|j�}|j|dddd�}|j|�S)	Nrr^g@g�rL���)rrrgr_rrhri�clip�astyper��fastNlMeansDenoisingr�)	r�rr"r_r rqrK�beta�denoiseds	         r<�bg_color_removalr^�s�������H�H�R�L�E��<�<��s�1�1�2�D��E��D��t�|�d�"�H��w�w�x��C�(�/�/����9�H��'�'��$��A�r�B�H��?�?�8�$�$rTc�V�ddlm}|j|�}|j|�}|S�Nr)�ImageEnhance)rgra�	Sharpness�enhance�r��factorra�enhancer_object�outs     r<�adjust_sharpnessrh�s*�� �"�,�,�R�0�O�
�
!�
!�&�
)�C��JrTc�V�ddlm}|j|�}|j|�}|Sr`)rgra�Contrastrcrds     r<�adjust_contrastrk�s*�� �"�+�+�B�/�O�
�
!�
!�&�
)�C��JrTc�V�ddlm}|j|�}|j|�}|Sr`)rgra�
Brightnessrcrds     r<�adjust_brightnessrn�s*�� �"�-�-�b�1�O�
�
!�
!�&�
)�C��JrTc�V�ddlm}|j|�}|j|�}|Sr`)rgra�Colorrcrds     r<�adjust_colorrq�s*�� �"�(�(��,�O�
�
!�
!�&�
)�C��JrTc���|jd�dk(rtd�yd}gd�}|D];}tj|�}|s�tj
j
||�}n|dk(�rQtjdd�}tjdd	k(rKtjd
||gtjtj��}|j�\}}	nItjd|gtjtj��}|j�\}}	tj
j|�r9t j#d
�|dz|zdzdz}
t	j$|�n#t j#d�|dz|zdzdz}
t'j(|
�yt j#d�|dz|zdzdz}
t'j(|
�y)Nr3Fz-PDF viewer is trying open other than PDF file�)�kpdf�acroread�xpdf�evincezxdg-openT�hpscan_ocr_rr?�ocrmypdf)�stdout�stderr�pypdfocrzOCR was successfulz  � �&z/OCR failed to generate, returning original filez+OCR was not called, returning original file)�endswith�printr�whichr�path�joinr@r��version_info�
subprocess�Popen�PIPE�STDOUT�communicate�isfiler"�debugr'r�execute)rH�ocr�
pdf_viewer�pdf_viewer_listr��vv�
output_ocrrgrzr{rGs           r<�merge_PDF_viewerr��s��������5�(�
�=�>���J�H�O�
���
�[�[��^��
������b�!�,�J��	�
�d�{��2�2�=�&�I�
����A��!�#��"�"�J�v�j�#A����`j�`q�`q�r�C��?�?�,�M�F�6��"�"�J�v�#6�j�o�o�U_�Uf�Uf�g�C��?�?�,�M�F�6�
�7�7�>�>�*�%��I�I�*�+��t�#�j�0�3�6��<�C��I�I�f���I�I�G�H��t�#�f�,�s�2�S�8�C�������	�	�?�@��4��&�(�3�.��4������rTc�t�d}	ddl}|S#t$r}t|�}Yd}~|Sd}~wtd�}Y|SxYw�Nr�Error occurred)rg�ImportError�str)�scanjet_flagrgr#s   r<�	check_pilr���K���L�+������ ���Z�����+��)�*������
�	7�$�7c�t�d}	ddl}|S#t$r}t|�}Yd}~|Sd}~wtd�}Y|SxYwr�)rr�r�)r�r"r#s   r<�check_numpyr��sK���L�+������ ���Z�����+��)�*����r�c�t�d}	ddl}|S#t$r}t|�}Yd}~|Sd}~wtd�}Y|SxYwr�)rr�r�)r�rr#s   r<�check_opencvr��r�r�c�V�d}	ddl}|S#	ddl}Y|S#td�}YY|SxYwxYwr�)r|ryr�)r�r|rys   r<�check_pypdfocrr�sE���L�/�����/�	/�����	/��-�.�L���s�
�(��
%�(�(c�t�d}	ddl}|S#t$r}t|�}Yd}~|Sd}~wtd�}Y|SxYwr�)�skimager�r�)r�r�r#s   r<�
check_skimager�sK���L�+������ ���Z�����+��)�*����r�c�(�d}	tt��dk\r&ddl}|j|jd�ddl}|Sddl}	|S#t$r}t|�}Yd}~|Sd}~wt$r}t|�}Yd}~|Sd}~wtd�}Y|SxYw)Nr�rr�r�)	rr�r�r�r�r�r�r��AttributeError)r�r�r�r#s    r<�check_tesserocr_imutilsr�s����L�
+��$�&�'�1�,�����V�]�]�C�0����
����� ���Z�����	� ���Z�����+��)�*����s)�:A�A�	B�A!�!B�-A>�>Bc�t�d}	ddl}|S#t$r}t|�}Yd}~|Sd}~wtd�}Y|SxYwr�)rr�r�)r�rr#s   r<�check_pypdf2r�-sK���L�+������ ���Z�����+��)�*����r�c���d}tj�}|jd�}|ddkr	ddl}|Sy#t$r}t|�}Yd}~|Sd}~wtd�}Y|SxYw)Nr�rr�r��zbar)r�r�r�r�r�r�)r�r�r�r�r#s     r<�
check_zbarr�8sw���L��(�(�*�J�
�
�
�3�
�C�
�1�v��|�	/�������	$��U��L����	/��-�.�L���s�8�	A%�A�A%c�,
�ddl}ddlm}g}i}|j\}}	}
t}t|tz
�}t|	tz
�}
t}d|cxkr|k�rn�n
d|cxkr|kr�nn�|dz
}|dz}||z}|d|zz}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<|dz
}|dz}||z
}|d|zz
}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<d|cxkr|k�rn�n
|
|cxkr|	kr�nn�|dz
}|dz}||z}|d|zz}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<|dz
}|dz}||z
}|d|zz
}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<||cxkr|k�rn�n
d|cxkr|	kr�nn�|d|zz
}||z
}|dz
}|dz}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<|d|zz}||z}|dz
}|dz}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<d|cxkr|k�rn�n
d|cxkr|	kr�nn�|d|zz
}||z
}|dz
}|dz}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<|d|zz}||z}|dz
}|dz}|||�||�f}|j\}}}t
d|dz
�D]:}t
d|dz
�D]&}|||f}|j|d|d|df��(�<t|�}|D]}|||j|�<�|j�}t|�}t|�}||d}t|�S)Nr��ior��rr
r�)
rr�r�r�punchhole_marginrr�rm�set�count�keysr�r=) �xcord�ycord�radiusrnr"r��lrQrVrW�channelsrXrYrZr[�s1�s2�s3�s4�myimgrGrHr/r��j�rgblist�mrD�d_keys�z_list�sortlist�ts                                 r<�
dominantcolorr�Hs�����
�A�
�A�"�i�i��E�6�8�
�B���(�(�
)�B���)�)�
*�B�
�B�	�E��E���E��B���Q�h���Q�h���v����q��x� ���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=��Q�h���Q�h���v����q��x� ���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=�
	
�E��E���U� 3�V� 3��Q�h���Q�h���v����q��x� ���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=��Q�h���Q�h���v����q��x� ���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=�	�U��U���U�!3�V�!3��q��x� ���v����a�i���a�i���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=��q��x� ���v����a�i���a�i���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=�
	
�E��B��Q��/��/��q��x� ���v����a�i���a�i���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=��q��x� ���v����a�i���a�i���B�r�E�2�b�5�L�!���K�K�	��A���q�!�A�#��	=�A��1�a��c�]�
=����!��*�����'�!�*�W�Q�Z���
�;�<�
=�	=�	�A��A�
�����!�'�'�!�*�
��
�V�V�X�F�
�&�\�F��f�~�H�	
�8�B�<��A���7�NrTc��|}t|�}t|�}|g}td|�D]U}td�D�cgc].}t||t|�|dz
z||||z
zz���0}	}|j	|	��W|Scc}w)Nrr?)rr�rr�rm)
�dominant_color�white_color�
pixelcount�n�s�f�RGB_listr�r��curr_vectors
          r<�lineargradientr��s����A�
�n��A�
�k��A��s�H�
�1�a�[�%��IN�q��R�A�s�1�Q�4�5��8�Q�q�S�>�A�a�D��1��I�">�>�?�R��R�����$�	%��O��	Ss�3Bc�\�ddl}ddlm}ddlm}ddlm}m}ddlm	}m
}ddlm}	ddl
m}	d}
ddlm}	d}
|j'|�}|j(d
dk(r	||�}n|||��}||�}|j(\}}t*}t-|t*z
�}t-|t*z
�}t*}t/|�}|j1ddd�}|||�}||||
��\}}}}t3|||�D�]\}}} d|cxkr|krnn
d|cxkr|ksVnd|cxkr|krnn
||cxkr|ks;nd|cxkr|krnn
d|cxkr|ks n||cxkr|ks�en�hd|cxkr|ks�tn�w|
dk(r	||| dz|j(�\}!}"n"|
d
k(r||f| dz|j(��\}!}"t5||| |�}#t3t7!�t7"��D]\}$}%|#d|#d|#ddf||$|%f<���|j9|�}&|&S#t$rdd	l
m}d
}
Y���wxYw)Nrr^r�)�rgba2rgb�rgb2gray)�hough_circle�hough_circle_peaks)r)�circler�)�diskr�)�img_as_ubyte�r�r?rV�"r)�total_num_peaks)rr
rL)rrgr_r�r��
skimage.colorr�r��skimage.transformr�r��skimage.featurer�skimage.drawr�r�r��skimage.utilr�rrr�rr�r��zipr�r�r�)'r�r"r_r�r�r�r�r�rr��
draw_importedr�r��	max_peaksrn�img_grayr rVrWrXrYrZr[rr�hough_radii�	hough_res�accums�cx�cy�radii�center_y�center_xr��rr�cc�dominantpixr�r��
finalimages'                                       r<�punchhole_removalr��s=�����0�B�%��'� �
�*�-��I�
�(�(�2�,�C��	�	�"�
����C�=���H�S�M�*����"�E��K�K�M�E�6�
�B���(�(�
)�B���)�)�
*�B�
�B��u��E��)�)�B��A�&�K��U�K�0�I�/�y�+�V_�`��F�B��E�&)�"�b�%�&8�P�"��(�F���
!�E�
!��H�(9�r�(9�
��
!�E�
!��X�(>��(>�
��
�B�
�Q��%:�F�%:�
�(�
"�U�
"��X�)>��)>���(��x��6�!�8�S�Y�Y�G���B��&�(��h��1�6�!�8�3�9�9�M���B�'��(�F�3�G�K��T�"�X�t�B�x�0�
P���A�&�q�>�;�q�>�;�q�>�3�O��A�a�C��
P�P� ���s�#�J����Y��%��
��s�H�H+�*H+c	��ddlm}ddl}ddl}ddl}ddl}|j
|d��}|j||j�}	tt|d|d|d��}
g}|jt|
ddz
d�t|
d|z
d�t|
d|z
d�gt|
ddzd�t|
d|zd	�t|
d|zd	�gf�|D]�\}}
|j
|d��}|j
|
d��}
|j|	||
�}|j\}}t!d|dz
�D](}t!d|dz
�D]}|||fd	k(s�d
|||f<��*��|j#|�}|S)Nrr^r�)�dtyperr
r�rL)rLrLrLrL)rgr_rrr@r�rrh�
COLOR_RGB2HSVr��rgb2hsvrmrr�inRangerr�r�)r��color�color_ranger_r"rr@r��npimg�hsv_img�	hsv_color�
boundariesrOrP�maskrWrVrHrGr�s                    r<�
color_dropoutr�s��������
�H�H�R�g�H�&�E��l�l�5�#�"3�"3�4�G��W�U�1�X�u�Q�x��q��:�;�I��J�����I�a�L�2�-�q�1�3�y��|�k�7Q�ST�3U�WZ�[d�ef�[g�ju�[u�wx�Wy�z��I�a�L�2�-�s�3�S��1���9S�UX�5Y�[^�_h�ij�_k�ny�_y�{~�[�A�B�C�%�	4�������%�g��.�����%�g��.���{�{�7�E�5�1���
�
�
�����&��(�#�	4�A��A�e�A�g�&�
4����1��I��$�"3�E�!�A�#�J�
4�	4�
	4�����'�J��rTc���tjd|z�ddlm}|j\}}|}|}||z
}||z
}|j||||f�}	|j
|	|d��}|S)Nz"edge_erase called with value=%d pxr)�ImageOps�white)�border�fill)r"r�rgrr�r��expand)
r��edge_erase_valuerrVrW�left�top�right�bottom�im1s
          r<�
edge_eraser#s|���I�I�2�4D�D�E���7�7�M�E�6��D�
�C��#�#�E�
�#�
#�F�
�'�'�4��f�e�,�
-�C�
����$4�'��	B�B�
�IrTc�r�|dz|dz|dz}}}t|||�}t|||�}||z
}||k(rd}nD||k(rd||z
|zzdzdz}n-||k(rd||z
|zzdzdz}n||k(rd||z
|zzdzdz}|dk(rd}n||z}|}t|dz�}t|dz�}tdz�}|||fS)	Nr}r�<ih�x��rLr
)rrr)	�r�g�b�mx�mn�dfrHr�r�s	         r<r�r�7s�����g�q��w��%��!�q�A�	�Q��1��B�	�Q��1��B�	�B��B�	�R�x�
��	�q��
�A�a�C��8�_�s�
"�c�)��	�q��
�A�a�C��8�_�s�
"�c�)��	�q��
�A�a�C��8�_�s�
"�c�)��	�Q�w�
���r�E��
�A��A��G��A��A��G��A��A�a�C��A��a��7�NrTc�x�d}	ddlm}|S#t$r}t|�}Yd}~|Sd}~wtd�}Y|SxYw)Nrrzr�)r�r{r�r�)r�r�r#s   r<�check_scipyrQsK���L�+�8�
���	� ���Z�����+��)�*����s��	9�&�9c�N�tjdk\r|jd�S|S)N)r?rzUTF-8)r�r��decode)r�s r<�_read_stringr\s$��
���6�!��x�x�� � ��rTc��	tjddgtjtj��}|j�\}}t	|�j�}|dk(rt	|�j�}t
jd|tj�}|r|jd�}|dSy#t$r
}Yd}~yd}~wwxYw)N�	tesseractz-v)r{rzrsz^tesseract ((?:\d+\.)+\d+).*rr)r�r�r�r�r�strip�re�searchr��group�OSError)r�stdout_version�version�
version_matchr0s     r<r�r�bs�������k�4�0����Q[�Q`�Q`�a��"#�-�-�/�����w�'�-�-�/���b�=�"�>�2�8�8�:�G��	�	�"A�7�B�D�D�Q�
��#�)�)�!�,�G��1�:���������s�B<C�	C�C)g��Q��?);�baserr�base.gr@rr�r�rr��	installerrrr�r�r�r=rSr\rxr�r�r�r�r�r�r�r�r�rrrr1rJr�rTr^rhrkrnrqr�r�r�r�r�r�r�r�r�r�r�r�r�rr�rrr��rTr<�<module>r*s��6!���	�
��	��"���	�����D�N!�H�,�B0�d2�@�.�4�(%�*�
�-�^�$$��6>�@K�Z��%�(����&�P	�	�	�	�	��&	�� o�d�6�p�F�(�4��rT

Zerion Mini Shell 1.0