wenwenyu / PICK-pytorch

Code for the paper "PICK: Processing Key Information Extraction from Documents using Improved Graph Learning-Convolutional Networks" (ICPR 2020)
https://arxiv.org/abs/2004.07464
MIT License
556 stars 193 forks source link

Code error in `sort_box_with_list` #23

Closed tengerye closed 4 years ago

tengerye commented 4 years ago

In your `documents.py' file, there is a snippet:

def sort_box_with_list(data: List[Tuple], left_right_first=True):
    def compare_key(x):
        #  x is (index, points, transcription, type) or (index, points, transcription)
        points = x[1]
        box = np.array([[points[0], points[1]], [points[2], points[3]], [points[4], points[5]], [points[6], points[7]]],
                       dtype=np.float32)
        rect = cv2.minAreaRect(box)  # Smallest rectangle around the box.
        # rect: center(x,y), (width, height), angle of rotation
        center = rect[0]
        if left_right_first:
            return center[1], center[0]
        else:
            return center[0], center[1]

    data = sorted(data, key=compare_key)
    return data

I think if you want left_right_first, you shall return center[0], center[1] instead of center[1], center[0]. Since center=(x, y).

wenwenyu commented 4 years ago

Thank you for bringing it to my attention. You are right. I have fixed it, and the default value of left_right_first is set to False.