Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate_clockwise_points issue on image pixel coordinate system #631

Open
starsky0426 opened this issue Sep 30, 2024 · 0 comments
Open

Comments

@starsky0426
Copy link

def validate_clockwise_points(points):

def validate_clockwise_points(points):
    """
    Validates that the points that the 4 points that dlimite a polygon are in clockwise order.
    """
    
    # if len(points) != 8:
    #     raise Exception("Points list not valid." + str(len(points)))
    
    # point = [
    #             [int(points[0]) , int(points[1])],
    #             [int(points[2]) , int(points[3])],
    #             [int(points[4]) , int(points[5])],
    #             [int(points[6]) , int(points[7])]
    #         ]
    # edge = [
    #             ( point[1][0] - point[0][0])*( point[1][1] + point[0][1]),
    #             ( point[2][0] - point[1][0])*( point[2][1] + point[1][1]),
    #             ( point[3][0] - point[2][0])*( point[3][1] + point[2][1]),
    #             ( point[0][0] - point[3][0])*( point[0][1] + point[3][1])
    # ]
    
    # summatory = edge[0] + edge[1] + edge[2] + edge[3];
    # if summatory>0:
    #     raise Exception("Points are not clockwise. The coordinates of bounding quadrilaterals have to be given in clockwise order. Regarding the correct interpretation of 'clockwise' remember that the image coordinate system used is the standard one, with the image origin at the upper left, the X axis extending to the right and Y axis extending downwards.")
    pts = [(points[j], points[j+1]) for j in range(0,len(points),2)]
    try:
        pdet = Polygon(pts)
    except:
        assert(0), ('not a valid polygon', pts)
    # The polygon should be valid.
    if not pdet.is_valid: 
        assert(0), ('polygon has intersection sides', pts)
    pRing = LinearRing(pts)
    if pRing.is_ccw:
        assert(0),  ("Points are not clockwise. The coordinates of bounding quadrilaterals have to be given in clockwise order. Regarding the correct interpretation of 'clockwise' remember that the image coordinate system used is the standard one, with the image origin at the upper left, the X axis extending to the right and Y axis extending downwards.")

The commented code and the working code has opposite result for a same input.

I think the issue is shapely do the computation on Descartian coordinate system, and we use image pixel coordinate system which have opposite result?

Maybe the judgement should be simplely changed to if not pRing.is_ccw:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant