如何将带圆圈的数字转换为数字? (①到1)

问题描述 投票:2回答:2

我想在OCR识别日语文本之后从我收到的字符串中转换数字。

例如,当我提取日期时:

③① 年 ⑫ 月 ①③ 日

我想将其转换为:

31 年 12 月 13 日

实现它的最佳方法是什么?

text encoding ocr utf cjk
2个回答
2
投票

我会用unicodedata

import unicodedata
print(unicodedata.normalize("NFKC","③① 年 ⑫ 月 ①③ 日"))

结果是,

31 年 12 月 13 日

这也会转换日文数字的其他变体,全宽数字。

import unicodedata
print(unicodedata.normalize("NFKC","123①②③123"))

123123123

2
投票

假设您已经在问题中对带圆圈的数字进行了OCR,那么简单的文本替换就足够了。这是你在Python中如何做到这一点:

def uncircle(s):
    for i in range(1, 21):
        s = s.replace(chr(0x245f + i), str(i))
    return s.replace('\u24ea', '0')

带圆圈的数字1到20是Unicode代码点0x2460到0x2473,带圆圈的数字0是Unicode代码点0x24ea。

© www.soinside.com 2019 - 2024. All rights reserved.