【问题标题】:Google Vision: Extract confidence of each word after extracting whole text using full_text_annotation.textGoogle Vision:使用 full_text_annotation.text 提取整个文本后提取每个单词的置信度
【发布时间】:2020-06-24 05:48:31
【问题描述】:

我正在使用

def detect_document(path):
     client = vision.ImageAnnotatorClient()

     with io.open(path, 'rb') as image_file:
        content = image_file.read()

     image = vision.types.Image(content=content)

     response = client.document_text_detection(image=image)

     text = response.full_text_annotation.text
     text = text.casefold()
     text = text.replace('(','')
     text = text.replace(')','')
     text = text.replace(':','')
     text = text.replace('.','')

     return text

从填写了手写的申请表中提取以下文本

a bank challan
bank branch abc mute deposit id 005saetm-0055 deposit date 14 ml 19
b personal information use capital letters and leave spaces between words
name muhammad hanif tiid
father's name muhammad yaqoob tiittitttt
computerized nic no 44 303-5214 345-3
d d m m y y y y
gender male age in years 22 date of birth  4-08-1999
domicile district mirpuskhas contact no 0333-7072258
please do not mention converted no
postal address anmol book depo naukot taluka jhuddo disstti mps
sindh
are you government servant yes
if yes, please attach noc
no
✓
religion muslim
✓
non-muslim o
c academic information
intermediate/hssc eng mirpuskhas bise match b 2016
matric/ssc seience bisemirpurkhang match a 2014
d any other certifications/diploma/professional degrees shorthand, dit, cit etc
name
le

然后使用正则表达式模式得到

现在我想为每个字段的所有处理创建日志

<name>

<origin>

muhammad hanif tiid 

</origin>

<originscore>

78.2

</originscore>

<final>

muhammad hanif

</final>

<corrections>

4

</corrections>

</name>

为此,我需要信心得分。我不知道如何获得此类解析字段的置信度分数。我试图获得每个提取词的信心,比如

A: 0.9900000095367432
.: 0.9900000095367432
Bank: 0.9900000095367432
Challan: 0.9900000095367432
Bank: 0.9900000095367432
Branch: 0.9900000095367432
ABC: 0.9900000095367432
mute: 0.6700000166893005
Deposit: 0.8500000238418579
ID: 0.8100000023841858
005SAETM: 0.6499999761581421
-: 0.2800000011920929
0055: 0.8500000238418579
Deposit: 0.9200000166893005
Date: 0.9900000095367432
14: 0.6399999856948853
ml: 0.5400000214576721
19: 0.550000011920929
B: 0.9900000095367432
.: 0.9900000095367432
Personal: 0.9900000095367432
Information: 0.9900000095367432
:: 0.9900000095367432
Use: 0.9399999976158142
CAPITAL: 0.9900000095367432
letters: 0.9900000095367432
and: 0.9900000095367432
leave: 0.9900000095367432
spaces: 0.9900000095367432
between: 0.9900000095367432
words: 0.9900000095367432
.: 0.9900000095367432
Name: 0.9900000095367432
:: 0.9800000190734863
MUHAMMAD: 0.9599999785423279
HANIF: 0.9399999976158142
TIID: 0.46000000834465027
Father: 0.9900000095367432
': 0.9800000190734863

这并不能解决问题。

接下来我可以尝试什么?

【问题讨论】:

    标签: python python-3.x google-cloud-platform google-vision


    【解决方案1】:

    替换这个sn-p的代码:

    text = response.full_text_annotation.text
         text = text.casefold()
         text = text.replace('(','')
         text = text.replace(')','')
         text = text.replace(':','')
         text = text.replace('.','')
    
         return text
    

    与:

    for page in response.full_text_annotation.pages:
        for block in page.blocks:
            for paragraph in block.paragraphs:
                for word in paragraph.words:
                    word_text = ''.join([
                        symbol.text for symbol in word.symbols
                    ])
                    print('{}: {}'.format(
                        word_text, word.confidence))
    

    Sample Output

    【讨论】:

    • 我也使用相同的逻辑来获得每个提取单词的置信度,如上所示,但这并不能解决问题。我需要获取每个短语而不是单个单词的置信度分数,例如 CNIC,它可能包含 '44601' '-' '6622831' '-' '3'。
    • 我认为目前不可能通过短语获得置信度分数。 OCR 提取的文本结构的层次结构是这样的:TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol
    • 据我所知确实如此。这个问题的任何替代解决方案?
    猜你喜欢
    • 1970-01-01
    • 2017-11-29
    • 2013-07-11
    • 2019-02-05
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多