Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 有没有办法指定文档的结构,以便google vision(OCR)在特定的庄园中处理文档?_Python 3.x_Google Cloud Vision - Fatal编程技术网

Python 3.x 有没有办法指定文档的结构,以便google vision(OCR)在特定的庄园中处理文档?

Python 3.x 有没有办法指定文档的结构,以便google vision(OCR)在特定的庄园中处理文档?,python-3.x,google-cloud-vision,Python 3.x,Google Cloud Vision,Google vision document text detection在检测符号和单词方面做得很好,但它严格按照行和段落将文本分组在一起,即使如此,在处理具有结构化文本的文档时,有时文本在逻辑上也不合适 我已经看过API文档,但找不到提供提示(语言除外)以更改其解析文档的方式的示例或参考。一个可能的解决方案可能是预处理文档,并使用google的api一次处理一个文档,但更愿意直接使用google的api,而不需要中间步骤 我使用的代码直接取自google的vision pdf python示

Google vision document text detection在检测符号和单词方面做得很好,但它严格按照行和段落将文本分组在一起,即使如此,在处理具有结构化文本的文档时,有时文本在逻辑上也不合适

我已经看过API文档,但找不到提供提示(语言除外)以更改其解析文档的方式的示例或参考。一个可能的解决方案可能是预处理文档,并使用google的api一次处理一个文档,但更愿意直接使用google的api,而不需要中间步骤

我使用的代码直接取自google的vision pdf python示例,使用该代码无需任何更改即可复制:


结果需要进行不同的分组,逻辑上,查看文档时,地址应该分组在一起。此处显示一个文档的结构(前4行):

在使用谷歌提供的样本并打印出结果以及页面、区块和段落编号之后,希望能够显示发生了什么。我们可以看到文件顶部的文本位于错误的位置,上面显示的信息分布在多个段落中,从第5块开始,应该从第0块开始:

********* Page Number: 0*************
********* Block Number: 0*************
********* Paragraph Number: 0*************
MAIN FLOOR 
BASEMENT 
TOTAL FINISHED AREA 
UNFINISHED" 
TOTAL AREA

[ snip ]

********* Block Number: 5*************
********* Paragraph Number: 10*************
Active 
2415 ST PETER STREET
********* Paragraph Number: 11*************
$500,000 (LP) 
R2222222 
Port Moody
********* Paragraph Number: 12*************
(SP) 
Board: V, Attached
********* Paragraph Number: 13*************
Port Moody Centre 
********* Paragraph Number: 15*************
V3G 2T5 
********* Paragraph Number: 16*************

[ SNIP ]
上述输出是使用以下方法生成的:

def annotate(_json):
    annotation = _json['responses'][0]['fullTextAnnotation']
    line = 0
    paranum = 0
    blcknum = 0
    pgenum = 0
    for page in annotation['pages']:
        print('********* Page Number: ' + str(pgenum) + '*************')
        pgenum += 1
        for block in page['blocks']:
            print('********* Block Number: ' + str(blcknum) + '*************')
            blcknum += 1
            for paragraph in block['paragraphs']:
                print('********* Paragraph Number: ' + str(paranum) + '*************')
                paranum += 1
                for word in paragraph['words']:
                    for symbol in word['symbols']:
                        print(symbol['text'], end='')
                        try:
                            bType = symbol['property']['detectedBreak']['type']
                            if bType == 'SPACE':
                                print(' ', end='')
                            if bType == 'EOL_SURE_SPACE':
                                print(' ')
                            if bType == 'LINE_BREAK':
                                print('')
                        except KeyError:
                            print('', end='')
                line += 1
********* Page Number: 0*************
********* Block Number: 0*************
********* Paragraph Number: 0*************
MAIN FLOOR 
BASEMENT 
TOTAL FINISHED AREA 
UNFINISHED" 
TOTAL AREA

[ snip ]

********* Block Number: 5*************
********* Paragraph Number: 10*************
Active 
2415 ST PETER STREET
********* Paragraph Number: 11*************
$500,000 (LP) 
R2222222 
Port Moody
********* Paragraph Number: 12*************
(SP) 
Board: V, Attached
********* Paragraph Number: 13*************
Port Moody Centre 
********* Paragraph Number: 15*************
V3G 2T5 
********* Paragraph Number: 16*************

[ SNIP ]
def annotate(_json):
    annotation = _json['responses'][0]['fullTextAnnotation']
    line = 0
    paranum = 0
    blcknum = 0
    pgenum = 0
    for page in annotation['pages']:
        print('********* Page Number: ' + str(pgenum) + '*************')
        pgenum += 1
        for block in page['blocks']:
            print('********* Block Number: ' + str(blcknum) + '*************')
            blcknum += 1
            for paragraph in block['paragraphs']:
                print('********* Paragraph Number: ' + str(paranum) + '*************')
                paranum += 1
                for word in paragraph['words']:
                    for symbol in word['symbols']:
                        print(symbol['text'], end='')
                        try:
                            bType = symbol['property']['detectedBreak']['type']
                            if bType == 'SPACE':
                                print(' ', end='')
                            if bType == 'EOL_SURE_SPACE':
                                print(' ')
                            if bType == 'LINE_BREAK':
                                print('')
                        except KeyError:
                            print('', end='')
                line += 1