
    i[                     4    d dl Z d dlZd Zd Zd Zd Zd ZdS )    Nc                 2    t          j        | d           d S )NT)exist_ok)osmakedirs)paths    %/code/app/lib/handwriting/io_utils.py
ensure_dirr	      s    Kt$$$$$$    c                     t           j                            | |          }t           j                            |          }|rt	          |           t          j        ||           d S N)r   r   joindirnamer	   cv2imwrite)out_dirfilenameframe	full_pathfolders        r   
dump_imager   
   sX    Wh//IW__Y''F 6K	5!!!!!r
   c                 V    t          j        |           }|t          d|            |S )NzImage not found: )r   imreadRuntimeError)
image_pathr   s     r   
load_imager      s2    Jz""E};z;;<<<Lr
   c                     |r| j         d         |k    rz|t          | j         d                   z  }t          | j         d         |z            }t          | j         d         |z            }t          j        | ||ft          j                  S | S )N   r   )interpolation)shapefloatintr   resize
INTER_AREA)r   	max_widthscalenew_wnew_hs        r   resize_if_neededr(      s     OU[^i//E%+a.111EKNU*++EKNU*++z%%s~NNNNLr
   c                 @    t          j        | t           j                  S r   )r   cvtColorCOLOR_BGR2GRAY)r   s    r   to_grayscaler,   "   s    <s1222r
   )r   r   r	   r   r   r(   r,    r
   r   <module>r.      sl    				 



% % %" " "    3 3 3 3 3r
   