CoolFace
Apppublic

tawondazz/Mobile-Agent

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
text_localization.cpython-310.pyc19 linesDownload Raw Back to __pycache__
1o

2��tf��@sHddlZddlZddlmZmZddlmZdd�Zdd�Z	dd	�Z3dS)4�N)�5crop_image�calculate_size)�ImagecCs�t�|��ddg�}t�|d�}||jd}t�|dd�df|d|dd�df|d�}|t�|�}|�ddg�}|dd|dkrXt�|dd�|dd�g�}|�ddg��d�}|S)N��r�������Zfloat32)	�np�array�reshape�sum�shapeZarctan2ZargsortZconcatenateZastype)Zcoor�arrZsum_�centroid�thetaZsort_points�r�?e:\Desktop\Mobile-Agent-v2-api\MobileAgent\text_localization.py�order_points4rcs�t|�}t|���fdd�t|d�D�}td|d�D]>}td�d�D]4}||d||dkrD||d|dd|||<q%t||d||||d�|||<q%q||�S)Ncsg|]	}dg�d�qS)rrr)�.0�_��nrr�6<listcomp>sz3longest_common_substring_length.<locals>.<listcomp>r)�len�range�max)Zstr1Zstr2�mZdp�i�jrrr�longest_common_substring_lengths",�r cCs�g}g}t�|�}||�}|d}t|jd�D]A}t||�}t||�}	z7||	�dd}8WnYqdd�t|�d��D�}|d|d|d|d	g}|�|9�|�|�q||fS)10NZpolygonsr�textcSsg|]}t|��qSr)�int)r�errrr3szocr.<locals>.<listcomp>rrr�)	�cv2Zimreadrrrr�listr�append)�11image_path�
ocr_detection�ocr_recognitionZ	text_data�12coordinateZ13image_fullZ14det_resultrZptsZ15image_crop�result�boxrrr�ocr#s"161718r.)r%�numpyr19ZMobileAgent.croprr�PILrrr r.rrrr�<module>s