AstarLight / Lets_OCR

A repository for OCR, which inlcudes some classical OCR algorithms Pytorch implementation such as CTPN, EAST and CRNN.
MIT License
656 stars 327 forks source link

这里 coords_left 和 coords_right 并无法保证相等 #101

Closed kingzcheung closed 2 months ago

kingzcheung commented 2 years ago

此处处理有比较严重的bug, 当 4个点中,有x 或者y 值相同时, coords_left 和 coords_right 就不一定会均分成左右2份。然后后面的处理直接造成 out of index 和有部分坐标被丢失。

https://github.com/AstarLight/Lets_OCR/blob/b2af7120a34d785434c96e820b6eb1aa69269d20/detector/ctpn/lib/generate_gt_anchor.py#L53

比如: [114.0, 459.0, 119.0, 476.0, 124.0, 476.0, 119.0, 461.0] 得到的 coords_left:: [[114.0, 459.0], [119.0, 476.0], [119.0, 461.0]] coords_right:: [[124.0, 476.0]]

new_box 变成了: [114.0, 459.0, 119.0, 476.0]

kingzcheung commented 2 years ago

重写后的 sortCoords


def sortCoords(box):
    '''
    将可能随机排列的坐标点,统一重新排列成左下、左上、右上、右下排列
    '''
    coords = [(box[i * 2],box[i*2+1]) for i in range(4)]
    coords.sort(key=lambda x:x[0])
    coords_left = coords[:2]
    coords_right = coords[2:]

    coords_left.sort(key=lambda y:y[1])
    coords_right.sort(key=lambda y:y[1],reverse=True)

    # merge
    new_box = []
    new_box += [list(x) for x in coords_left]
    new_box += [list(x) for x in coords_right]

    # 二维转一维
    new_box = [i for item in new_box for i in item]
    # print('coords_left::',coords_left)
    # print('coords_right::',coords_right)
    return new_box