根据国家重新排列车牌字符

我正在做一个车牌/车牌识别项目,我正在完成阶段但有一个小问题,我已经成功识别了字符,请考虑以下示例:

这是一个输入图像,我得到的预测为 2791 2g rj14

尽你所能,ocr 做得很好,但安排被破坏了(破坏了整个目的)。有时它会以正确的顺序输出,但有时却不会,所以当它没有以正确的顺序输出时,我正在尝试开发一种算法,该算法将预测num_plate字符串作为输入并根据我的国家/地区重新排列它(印度)。

下面是一些图片,它们告诉我们印度号码/车牌的格式。

此外,我已经收集了所有州,但现在,我只想为 3 个州做:德里 (DL)、哈里亚纳邦 (HR)、北方邦 (UP)。更多信息:https : //en.wikipedia.org/wiki/List_of_Regional_Transport_Office_districts_in_India

total_states_list = [
    'AN','AP','AR','AS','BR','CG','CH','DD','DL','DN','GA','GJ','HR','HP','JH','JK','KA','KL',
    'LD','MH','ML','MN','MP','MZ','NL','OD','PB','PY','RJ','SK','TN','TR','TS','UK','UP','WB'
]

district_codes = {
    'DL': ['1','2','3','4','5','6','7','8','9','10','11','12','13'],
    'HR': [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
            40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,
            71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99
    ]
}

因此,我一直在尝试,但无法提出一种算法,如果不是,则按所需序列重新排列序列。任何帮助将非常感激。

有关 OCR 的详细信息

使用keras-ocr,我得到输入图像的以下输出:

[
  ('hrlz',  array([[ 68.343796,  42.088367],
                   [196.68803 ,  26.907867],
                   [203.00832 ,  80.343094],
                   [ 74.66408 ,  95.5236  ]], dtype=float32)), 
  ('c1044', array([[ 50.215836, 113.09602 ],
                   [217.72466 ,  92.58473 ],
                   [224.3968  , 147.07387 ],
                   [ 56.887985, 167.58516 ]], dtype=float32))
]

来源:https : //keras-ocr.readthedocs.io/en/latest/examples/using_pretrained_models.html

keras_ocr.tools.drawAnnotations他们里面我想得到预测框。所以我找到了这个文件并找到了drawAnnotations函数的实现,这里是:

def drawAnnotations(image, predictions, ax=None):
  if ax is None:
        _, ax = plt.subplots()
    ax.imshow(drawBoxes(image=image, boxes=predictions, boxes_format='predictions'))
    predictions = sorted(predictions, key=lambda p: p[1][:, 1].min())
    left = []
    right = []
    for word, box in predictions:
        if box[:, 0].min() < image.shape[1] / 2:
            left.append((word, box))
        else:
            right.append((word, box))
    ax.set_yticks([])
    ax.set_xticks([])
    for side, group in zip(['left', 'right'], [left, right]):
        for index, (text, box) in enumerate(group):
            y = 1 - (index / len(group))
            xy = box[0] / np.array([image.shape[1], image.shape[0]])
            xy[1] = 1 - xy[1]
            ax.annotate(s=text,
                        xy=xy,
                        xytext=(-0.05 if side == 'left' else 1.05, y),
                        xycoords='axes fraction',
                        arrowprops={
                            'arrowstyle': '->',
                            'color': 'r'
                        },
                        color='r',
                        fontsize=14,
                        horizontalalignment='right' if side == 'left' else 'left')
    return ax

我应该如何获取 (x,y,w,h) 然后根据 number_plate bbox 的 y/x 以某种方式排序/打印?

编辑 - 2

我设法获得了字符的边界框,如下图所示:

使用函数cv2.polylines(box),哪里box是我之前粘贴输出的相同坐标。现在我怎样才能按照从左到右的顺序打印它们……使用评论中人们建议的 y/x。

以上是根据国家重新排列车牌字符的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>