argman / EAST

A tensorflow implementation of EAST text detector
GNU General Public License v3.0
3.02k stars 1.05k forks source link

Area of Polygon #88

Open enmengyi opened 6 years ago

enmengyi commented 6 years ago

Hello, thanks for your code so much. In icdar.py, I found the function polygon_area(poly) you defined to compute the area of a polygon:

def polygon_area(poly):

    edge = [
        (poly[1][0] - poly[0][0]) * (poly[1][1] + poly[0][1]),
        (poly[2][0] - poly[1][0]) * (poly[2][1] + poly[1][1]),
        (poly[3][0] - poly[2][0]) * (poly[3][1] + poly[2][1]),
        (poly[0][0] - poly[3][0]) * (poly[0][1] + poly[3][1])
    ]

    return np.sum(edge)/2.

It means that

area = [(x2-x1)*(y2+y1) + (x3-x2)*(y3+y2) + (x4-x3)*(y4+y3) + (x1-x4)*(y1+y4)] / 2

But I can't understand why. Would you like to give some explanation of this? Thanks~

argman commented 6 years ago

I just search and find this magic works..

UpCoder commented 6 years ago

I also confused about it. Do you understand it? @enmengyi @argman Thanks~ And I found the result is negative number or will adjust the position of points.

UpCoder commented 6 years ago

I found some information about this problem. you can see zhihu or math