o
    'j                     @   sJ   d dl Zd dlmZ 	 dd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )    N)Polygonc                 C   s    t tj| |gdd}t|jS )N   Zaxis)r   npstackfloatarea)xyZpolygon r   n/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddleocr/ppocr/utils/e2e_metric/polygon_fast.pyr      s   
r   c                 C   s   t |}t | }t |}t | }t |}t |}	t |}
t |}t ||}t ||
}t d|| }t ||	}t ||}t d|| }|| S )z
    This helper determine if both polygons are intersecting with each others with an approximation method.
    Area of intersection represented by the minimum bounding rectangular [xmin, ymin, xmax, ymax]
    g        )r   maxminminimummaximum)det_xdet_ygt_xgt_yZdet_ymaxZdet_xmaxZdet_yminZdet_xminZgt_ymaxZgt_xmaxZgt_yminZgt_xminZall_min_ymaxZall_max_yminZintersect_heightsZall_min_xmaxZall_max_xminZintersect_widthsr   r   r   approx_area_of_intersection"   s   







r   c                 C   H   t tj| |gddd}t tj||gddd}t||jS Nr   r   r   )r   r   r   bufferr   intersectionr   r   r   r   r   p1Zp2r   r   r   area_of_intersection=      r   c                 C   r   r   )r   r   r   r   r   unionr   r   r   r   r   area_of_unionC   r   r   c                 C   s    t | |||t| |||d  S )N      ?)r   r   r   r   r   r   r   r   r   iouI   s   r"   c                 C   s   t | |||t| |d  S )zU
    This helper determine the fraction of intersection area over detection area
    r    )r   r   r!   r   r   r   iodN   s   r#   )
numpyr   Zshapely.geometryr   r   r   r   r   r"   r#   r   r   r   r   <module>   s   