Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
cad701d4
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cad701d4
编写于
10月 24, 2022
作者:
文幕地方
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix benckmark error when benckmark=false
上级
14efc410
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
120 addition
and
93 deletion
+120
-93
paddleocr.py
paddleocr.py
+1
-1
ppstructure/pdf2word/pdf2word.py
ppstructure/pdf2word/pdf2word.py
+111
-89
ppstructure/recovery/requirements.txt
ppstructure/recovery/requirements.txt
+2
-1
ppstructure/table/predict_table.py
ppstructure/table/predict_table.py
+6
-2
未找到文件。
paddleocr.py
浏览文件 @
cad701d4
...
@@ -47,7 +47,7 @@ __all__ = [
...
@@ -47,7 +47,7 @@ __all__ = [
]
]
SUPPORT_DET_MODEL
=
[
'DB'
]
SUPPORT_DET_MODEL
=
[
'DB'
]
VERSION
=
'2.6.
0.3
'
VERSION
=
'2.6.
1.0
'
SUPPORT_REC_MODEL
=
[
'CRNN'
,
'SVTR_LCNet'
]
SUPPORT_REC_MODEL
=
[
'CRNN'
,
'SVTR_LCNet'
]
BASE_DIR
=
os
.
path
.
expanduser
(
"~/.paddleocr/"
)
BASE_DIR
=
os
.
path
.
expanduser
(
"~/.paddleocr/"
)
...
...
ppstructure/pdf2word/pdf2word.py
浏览文件 @
cad701d4
# copyright (c) 2022 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
sys
import
sys
import
tarfile
import
tarfile
import
os
import
os
import
time
import
time
import
datetime
import
datetime
import
functools
import
functools
import
cv2
import
cv2
import
platform
import
platform
import
numpy
as
np
import
numpy
as
np
...
@@ -20,7 +34,6 @@ root = os.path.abspath(os.path.join(file, '../../'))
...
@@ -20,7 +34,6 @@ root = os.path.abspath(os.path.join(file, '../../'))
sys
.
path
.
append
(
file
)
sys
.
path
.
append
(
file
)
sys
.
path
.
insert
(
0
,
root
)
sys
.
path
.
insert
(
0
,
root
)
from
ppstructure.predict_system
import
StructureSystem
,
save_structure_res
from
ppstructure.predict_system
import
StructureSystem
,
save_structure_res
from
ppstructure.utility
import
parse_args
,
draw_structure_result
from
ppstructure.utility
import
parse_args
,
draw_structure_result
from
ppocr.utils.network
import
download_with_progressbar
from
ppocr.utils.network
import
download_with_progressbar
...
@@ -32,13 +45,17 @@ __VERSION__ = "0.2.2"
...
@@ -32,13 +45,17 @@ __VERSION__ = "0.2.2"
URLs_EN
=
{
URLs_EN
=
{
# 下载超英文轻量级PP-OCRv3模型的检测模型并解压
# 下载超英文轻量级PP-OCRv3模型的检测模型并解压
"en_PP-OCRv3_det_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar"
,
"en_PP-OCRv3_det_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar"
,
# 下载英文轻量级PP-OCRv3模型的识别模型并解压
# 下载英文轻量级PP-OCRv3模型的识别模型并解压
"en_PP-OCRv3_rec_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_infer.tar"
,
"en_PP-OCRv3_rec_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_infer.tar"
,
# 下载超轻量级英文表格英文模型并解压
# 下载超轻量级英文表格英文模型并解压
"en_ppstructure_mobile_v2.0_SLANet_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/en_ppstructure_mobile_v2.0_SLANet_infer.tar"
,
"en_ppstructure_mobile_v2.0_SLANet_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/en_ppstructure_mobile_v2.0_SLANet_infer.tar"
,
# 英文版面分析模型
# 英文版面分析模型
"picodet_lcnet_x1_0_fgd_layout_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_infer.tar"
,
"picodet_lcnet_x1_0_fgd_layout_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_infer.tar"
,
}
}
DICT_EN
=
{
DICT_EN
=
{
"rec_char_dict_path"
:
"en_dict.txt"
,
"rec_char_dict_path"
:
"en_dict.txt"
,
...
@@ -47,21 +64,24 @@ DICT_EN = {
...
@@ -47,21 +64,24 @@ DICT_EN = {
URLs_CN
=
{
URLs_CN
=
{
# 下载超中文轻量级PP-OCRv3模型的检测模型并解压
# 下载超中文轻量级PP-OCRv3模型的检测模型并解压
"cn_PP-OCRv3_det_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar"
,
"cn_PP-OCRv3_det_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar"
,
# 下载中文轻量级PP-OCRv3模型的识别模型并解压
# 下载中文轻量级PP-OCRv3模型的识别模型并解压
"cn_PP-OCRv3_rec_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar"
,
"cn_PP-OCRv3_rec_infer"
:
"https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar"
,
# 下载超轻量级英文表格英文模型并解压
# 下载超轻量级英文表格英文模型并解压
"cn_ppstructure_mobile_v2.0_SLANet_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/en_ppstructure_mobile_v2.0_SLANet_infer.tar"
,
"cn_ppstructure_mobile_v2.0_SLANet_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/en_ppstructure_mobile_v2.0_SLANet_infer.tar"
,
# 中文版面分析模型
# 中文版面分析模型
"picodet_lcnet_x1_0_fgd_layout_cdla_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_cdla_infer.tar"
,
"picodet_lcnet_x1_0_fgd_layout_cdla_infer"
:
"https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_cdla_infer.tar"
,
}
}
DICT_CN
=
{
DICT_CN
=
{
"rec_char_dict_path"
:
"ppocr_keys_v1.txt"
,
"rec_char_dict_path"
:
"ppocr_keys_v1.txt"
,
"layout_dict_path"
:
"layout_cdla_dict.txt"
,
"layout_dict_path"
:
"layout_cdla_dict.txt"
,
}
}
def
QImageToCvMat
(
incomingImage
)
->
np
.
array
:
def
QImageToCvMat
(
incomingImage
)
->
np
.
array
:
'''
'''
Converts a QImage into an opencv MAT format
Converts a QImage into an opencv MAT format
...
@@ -98,7 +118,7 @@ def readImage(image_file) -> list:
...
@@ -98,7 +118,7 @@ def readImage(image_file) -> list:
img
=
cv2
.
imread
(
image_file
,
cv2
.
IMREAD_COLOR
)
img
=
cv2
.
imread
(
image_file
,
cv2
.
IMREAD_COLOR
)
if
img
is
not
None
:
if
img
is
not
None
:
imgs
=
[
img
]
imgs
=
[
img
]
return
imgs
return
imgs
...
@@ -106,7 +126,7 @@ class Worker(QThread):
...
@@ -106,7 +126,7 @@ class Worker(QThread):
progressBarValue
=
Signal
(
int
)
progressBarValue
=
Signal
(
int
)
progressBarRange
=
Signal
(
int
)
progressBarRange
=
Signal
(
int
)
endsignal
=
Signal
()
endsignal
=
Signal
()
exceptedsignal
=
Signal
(
str
)
#发送一个异常信号
exceptedsignal
=
Signal
(
str
)
#发送一个异常信号
loopFlag
=
True
loopFlag
=
True
def
__init__
(
self
,
predictors
,
save_pdf
,
vis_font_path
,
use_pdf2docx_api
):
def
__init__
(
self
,
predictors
,
save_pdf
,
vis_font_path
,
use_pdf2docx_api
):
...
@@ -120,7 +140,7 @@ class Worker(QThread):
...
@@ -120,7 +140,7 @@ class Worker(QThread):
self
.
outputDir
=
None
self
.
outputDir
=
None
self
.
totalPageCnt
=
0
self
.
totalPageCnt
=
0
self
.
pageCnt
=
0
self
.
pageCnt
=
0
self
.
setStackSize
(
1024
*
1024
)
self
.
setStackSize
(
1024
*
1024
)
def
setImagePath
(
self
,
imagePaths
):
def
setImagePath
(
self
,
imagePaths
):
self
.
imagePaths
=
imagePaths
self
.
imagePaths
=
imagePaths
...
@@ -130,7 +150,7 @@ class Worker(QThread):
...
@@ -130,7 +150,7 @@ class Worker(QThread):
def
setOutputDir
(
self
,
outputDir
):
def
setOutputDir
(
self
,
outputDir
):
self
.
outputDir
=
outputDir
self
.
outputDir
=
outputDir
def
setPDFParser
(
self
,
enabled
):
def
setPDFParser
(
self
,
enabled
):
self
.
use_pdf2docx_api
=
enabled
self
.
use_pdf2docx_api
=
enabled
...
@@ -167,10 +187,10 @@ class Worker(QThread):
...
@@ -167,10 +187,10 @@ class Worker(QThread):
try
:
try
:
convert_info_docx
(
imgs
,
all_res
,
self
.
outputDir
,
img_name
)
convert_info_docx
(
imgs
,
all_res
,
self
.
outputDir
,
img_name
)
except
Exception
as
ex
:
except
Exception
as
ex
:
print
(
"error in layout recovery image:{}, err msg: {}"
.
print
(
"error in layout recovery image:{}, err msg: {}"
.
format
(
format
(
img_name
,
ex
))
img_name
,
ex
))
print
(
"Predict time : {:.3f}s"
.
format
(
time_dict
[
'all'
]))
print
(
"Predict time : {:.3f}s"
.
format
(
time_dict
[
'all'
]))
print
(
'result save to {}'
.
format
(
self
.
outputDir
))
print
(
'result save to {}'
.
format
(
self
.
outputDir
))
def
run
(
self
):
def
run
(
self
):
self
.
resetPageCnt
()
self
.
resetPageCnt
()
...
@@ -185,10 +205,11 @@ class Worker(QThread):
...
@@ -185,10 +205,11 @@ class Worker(QThread):
and
os
.
path
.
basename
(
image_file
)[
-
3
:]
==
'pdf'
:
and
os
.
path
.
basename
(
image_file
)[
-
3
:]
==
'pdf'
:
self
.
totalPageCnt
+=
1
self
.
totalPageCnt
+=
1
self
.
progressBarRange
.
emit
(
self
.
totalPageCnt
)
self
.
progressBarRange
.
emit
(
self
.
totalPageCnt
)
print
(
'===============using use_pdf2docx_api==============='
)
print
(
'===============using use_pdf2docx_api==============='
)
img_name
=
os
.
path
.
basename
(
image_file
).
split
(
'.'
)[
0
]
img_name
=
os
.
path
.
basename
(
image_file
).
split
(
'.'
)[
0
]
docx_file
=
os
.
path
.
join
(
docx_file
=
os
.
path
.
join
(
self
.
outputDir
,
self
.
outputDir
,
'{}.docx'
.
format
(
img_name
))
'{}.docx'
.
format
(
img_name
))
cv
=
Converter
(
image_file
)
cv
=
Converter
(
image_file
)
cv
.
convert
(
docx_file
)
cv
.
convert
(
docx_file
)
cv
.
close
()
cv
.
close
()
...
@@ -201,13 +222,14 @@ class Worker(QThread):
...
@@ -201,13 +222,14 @@ class Worker(QThread):
if
len
(
imgs
)
==
0
:
if
len
(
imgs
)
==
0
:
continue
continue
img_name
=
os
.
path
.
basename
(
image_file
).
split
(
'.'
)[
0
]
img_name
=
os
.
path
.
basename
(
image_file
).
split
(
'.'
)[
0
]
os
.
makedirs
(
os
.
path
.
join
(
self
.
outputDir
,
img_name
),
exist_ok
=
True
)
os
.
makedirs
(
os
.
path
.
join
(
self
.
outputDir
,
img_name
),
exist_ok
=
True
)
self
.
ppocrPrecitor
(
imgs
,
img_name
)
self
.
ppocrPrecitor
(
imgs
,
img_name
)
# file processed
# file processed
self
.
endsignal
.
emit
()
self
.
endsignal
.
emit
()
# self.exec()
# self.exec()
except
Exception
as
e
:
except
Exception
as
e
:
self
.
exceptedsignal
.
emit
(
str
(
e
))
# 将异常发送给UI进程
self
.
exceptedsignal
.
emit
(
str
(
e
))
# 将异常发送给UI进程
class
APP_Image2Doc
(
QWidget
):
class
APP_Image2Doc
(
QWidget
):
...
@@ -222,8 +244,7 @@ class APP_Image2Doc(QWidget):
...
@@ -222,8 +244,7 @@ class APP_Image2Doc(QWidget):
self
.
screenShot
=
None
self
.
screenShot
=
None
self
.
save_pdf
=
False
self
.
save_pdf
=
False
self
.
output_dir
=
None
self
.
output_dir
=
None
self
.
vis_font_path
=
os
.
path
.
join
(
root
,
self
.
vis_font_path
=
os
.
path
.
join
(
root
,
"doc"
,
"fonts"
,
"simfang.ttf"
)
"doc"
,
"fonts"
,
"simfang.ttf"
)
self
.
use_pdf2docx_api
=
False
self
.
use_pdf2docx_api
=
False
# ProgressBar
# ProgressBar
...
@@ -239,14 +260,16 @@ class APP_Image2Doc(QWidget):
...
@@ -239,14 +260,16 @@ class APP_Image2Doc(QWidget):
self
.
downloadModels
(
URLs_CN
)
self
.
downloadModels
(
URLs_CN
)
# 初始化模型
# 初始化模型
predictors
=
{
predictors
=
{
'EN'
:
self
.
initPredictor
(
'EN'
),
'EN'
:
self
.
initPredictor
(
'EN'
),
'CN'
:
self
.
initPredictor
(
'CN'
),
'CN'
:
self
.
initPredictor
(
'CN'
),
}
}
# 设置工作进程
# 设置工作进程
self
.
_thread
=
Worker
(
predictors
,
self
.
save_pdf
,
self
.
vis_font_path
,
self
.
use_pdf2docx_api
)
self
.
_thread
=
Worker
(
predictors
,
self
.
save_pdf
,
self
.
vis_font_path
,
self
.
_thread
.
progressBarValue
.
connect
(
self
.
handleProgressBarUpdateSingal
)
self
.
use_pdf2docx_api
)
self
.
_thread
.
progressBarValue
.
connect
(
self
.
handleProgressBarUpdateSingal
)
self
.
_thread
.
endsignal
.
connect
(
self
.
handleEndsignalSignal
)
self
.
_thread
.
endsignal
.
connect
(
self
.
handleEndsignalSignal
)
# self._thread.finished.connect(QObject.deleteLater)
# self._thread.finished.connect(QObject.deleteLater)
self
.
_thread
.
progressBarRange
.
connect
(
self
.
handleProgressBarRangeSingal
)
self
.
_thread
.
progressBarRange
.
connect
(
self
.
handleProgressBarRangeSingal
)
...
@@ -285,7 +308,7 @@ class APP_Image2Doc(QWidget):
...
@@ -285,7 +308,7 @@ class APP_Image2Doc(QWidget):
layout
.
addWidget
(
self
.
PDFParserButton
,
0
,
3
,
1
,
1
)
layout
.
addWidget
(
self
.
PDFParserButton
,
0
,
3
,
1
,
1
)
self
.
PDFParserButton
.
clicked
.
connect
(
self
.
PDFParserButton
.
clicked
.
connect
(
functools
.
partial
(
self
.
handleStartSignal
,
'CN'
,
True
))
functools
.
partial
(
self
.
handleStartSignal
,
'CN'
,
True
))
self
.
showResultButton
=
QPushButton
(
"显示结果"
)
self
.
showResultButton
=
QPushButton
(
"显示结果"
)
self
.
showResultButton
.
setIcon
(
QIcon
(
QPixmap
(
"./icons/folder-open.png"
)))
self
.
showResultButton
.
setIcon
(
QIcon
(
QPixmap
(
"./icons/folder-open.png"
)))
layout
.
addWidget
(
self
.
showResultButton
,
0
,
4
,
1
,
1
)
layout
.
addWidget
(
self
.
showResultButton
,
0
,
4
,
1
,
1
)
...
@@ -294,8 +317,7 @@ class APP_Image2Doc(QWidget):
...
@@ -294,8 +317,7 @@ class APP_Image2Doc(QWidget):
# ProgressBar
# ProgressBar
layout
.
addWidget
(
self
.
pb
,
2
,
0
,
1
,
5
)
layout
.
addWidget
(
self
.
pb
,
2
,
0
,
1
,
5
)
# time estimate label
# time estimate label
self
.
timeEstLabel
=
QLabel
(
self
.
timeEstLabel
=
QLabel
((
"Time Left: --"
))
(
"Time Left: --"
))
layout
.
addWidget
(
self
.
timeEstLabel
,
3
,
0
,
1
,
5
)
layout
.
addWidget
(
self
.
timeEstLabel
,
3
,
0
,
1
,
5
)
self
.
setLayout
(
layout
)
self
.
setLayout
(
layout
)
...
@@ -303,11 +325,8 @@ class APP_Image2Doc(QWidget):
...
@@ -303,11 +325,8 @@ class APP_Image2Doc(QWidget):
def
downloadModels
(
self
,
URLs
):
def
downloadModels
(
self
,
URLs
):
# using custom model
# using custom model
tar_file_name_list
=
[
tar_file_name_list
=
[
'inference.pdiparams'
,
'inference.pdiparams'
,
'inference.pdiparams.info'
,
'inference.pdiparams.info'
,
'inference.pdmodel'
,
'model.pdiparams'
,
'model.pdiparams.info'
,
'inference.pdmodel'
,
'model.pdiparams'
,
'model.pdiparams.info'
,
'model.pdmodel'
'model.pdmodel'
]
]
model_path
=
os
.
path
.
join
(
root
,
'inference'
)
model_path
=
os
.
path
.
join
(
root
,
'inference'
)
...
@@ -325,9 +344,10 @@ class APP_Image2Doc(QWidget):
...
@@ -325,9 +344,10 @@ class APP_Image2Doc(QWidget):
try
:
try
:
download_with_progressbar
(
url
,
tarpath
)
download_with_progressbar
(
url
,
tarpath
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Error occurred when downloading file, error message:"
)
print
(
"Error occurred when downloading file, error message:"
)
print
(
e
)
print
(
e
)
# unzip model tar
# unzip model tar
try
:
try
:
with
tarfile
.
open
(
tarpath
,
'r'
)
as
tarObj
:
with
tarfile
.
open
(
tarpath
,
'r'
)
as
tarObj
:
...
@@ -341,13 +361,12 @@ class APP_Image2Doc(QWidget):
...
@@ -341,13 +361,12 @@ class APP_Image2Doc(QWidget):
if
filename
is
None
:
if
filename
is
None
:
continue
continue
file
=
tarObj
.
extractfile
(
member
)
file
=
tarObj
.
extractfile
(
member
)
with
open
(
with
open
(
os
.
path
.
join
(
storage_dir
,
filename
),
os
.
path
.
join
(
storage_dir
,
filename
),
'wb'
)
as
f
:
'wb'
)
as
f
:
f
.
write
(
file
.
read
())
f
.
write
(
file
.
read
())
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Error occurred when unziping file, error message:"
)
print
(
"Error occurred when unziping file, error message:"
)
print
(
e
)
print
(
e
)
def
initPredictor
(
self
,
lang
=
'EN'
):
def
initPredictor
(
self
,
lang
=
'EN'
):
# init predictor args
# init predictor args
...
@@ -356,50 +375,53 @@ class APP_Image2Doc(QWidget):
...
@@ -356,50 +375,53 @@ class APP_Image2Doc(QWidget):
args
.
ocr
=
True
args
.
ocr
=
True
args
.
recovery
=
True
args
.
recovery
=
True
args
.
save_pdf
=
self
.
save_pdf
args
.
save_pdf
=
self
.
save_pdf
args
.
table_char_dict_path
=
os
.
path
.
join
(
root
,
args
.
table_char_dict_path
=
os
.
path
.
join
(
root
,
"ppocr"
,
"utils"
,
"dict"
,
"ppocr"
,
"utils"
,
"dict"
,
"table_structure_dict.txt"
)
"table_structure_dict.txt"
)
if
lang
==
'EN'
:
if
lang
==
'EN'
:
args
.
det_model_dir
=
os
.
path
.
join
(
root
,
# 此处从这里找到模型存放位置
args
.
det_model_dir
=
os
.
path
.
join
(
"inference"
,
"en_PP-OCRv3_det_infer"
)
root
,
# 此处从这里找到模型存放位置
args
.
rec_model_dir
=
os
.
path
.
join
(
root
,
"inference"
,
"inference"
,
"en_PP-OCRv3_rec_infer"
)
"en_PP-OCRv3_det_infer"
)
args
.
table_model_dir
=
os
.
path
.
join
(
root
,
args
.
rec_model_dir
=
os
.
path
.
join
(
root
,
"inference"
,
"inference"
,
"en_ppstructure_mobile_v2.0_SLANet_infer"
)
"en_PP-OCRv3_rec_infer"
)
args
.
output
=
os
.
path
.
join
(
root
,
"output"
)
# 结果保存路径
args
.
table_model_dir
=
os
.
path
.
join
(
args
.
layout_model_dir
=
os
.
path
.
join
(
root
,
root
,
"inference"
,
"en_ppstructure_mobile_v2.0_SLANet_infer"
)
"inference"
,
"picodet_lcnet_x1_0_fgd_layout_infer"
)
args
.
output
=
os
.
path
.
join
(
root
,
"output"
)
# 结果保存路径
args
.
layout_model_dir
=
os
.
path
.
join
(
root
,
"inference"
,
"picodet_lcnet_x1_0_fgd_layout_infer"
)
lang_dict
=
DICT_EN
lang_dict
=
DICT_EN
elif
lang
==
'CN'
:
elif
lang
==
'CN'
:
args
.
det_model_dir
=
os
.
path
.
join
(
root
,
# 此处从这里找到模型存放位置
args
.
det_model_dir
=
os
.
path
.
join
(
"inference"
,
"cn_PP-OCRv3_det_infer"
)
root
,
# 此处从这里找到模型存放位置
args
.
rec_model_dir
=
os
.
path
.
join
(
root
,
"inference"
,
"inference"
,
"cn_PP-OCRv3_rec_infer"
)
"cn_PP-OCRv3_det_infer"
)
args
.
table_model_dir
=
os
.
path
.
join
(
root
,
args
.
rec_model_dir
=
os
.
path
.
join
(
root
,
"inference"
,
"inference"
,
"cn_ppstructure_mobile_v2.0_SLANet_infer"
)
"cn_PP-OCRv3_rec_infer"
)
args
.
output
=
os
.
path
.
join
(
root
,
"output"
)
# 结果保存路径
args
.
table_model_dir
=
os
.
path
.
join
(
args
.
layout_model_dir
=
os
.
path
.
join
(
root
,
root
,
"inference"
,
"cn_ppstructure_mobile_v2.0_SLANet_infer"
)
"inference"
,
"picodet_lcnet_x1_0_fgd_layout_cdla_infer"
)
args
.
output
=
os
.
path
.
join
(
root
,
"output"
)
# 结果保存路径
args
.
layout_model_dir
=
os
.
path
.
join
(
root
,
"inference"
,
"picodet_lcnet_x1_0_fgd_layout_cdla_infer"
)
lang_dict
=
DICT_CN
lang_dict
=
DICT_CN
else
:
else
:
raise
ValueError
(
"Unsupported language"
)
raise
ValueError
(
"Unsupported language"
)
args
.
rec_char_dict_path
=
os
.
path
.
join
(
root
,
args
.
rec_char_dict_path
=
os
.
path
.
join
(
root
,
"ppocr"
,
"utils"
,
"ppocr"
,
"utils"
,
lang_dict
[
'rec_char_dict_path'
])
lang_dict
[
'rec_char_dict_path'
])
args
.
layout_dict_path
=
os
.
path
.
join
(
root
,
"ppocr"
,
"utils"
,
"dict"
,
args
.
layout_dict_path
=
os
.
path
.
join
(
root
,
"layout_dict"
,
"ppocr"
,
"utils"
,
"dict"
,
"layout_dict"
,
lang_dict
[
'layout_dict_path'
])
lang_dict
[
'layout_dict_path'
])
# init predictor
# init predictor
return
StructureSystem
(
args
)
return
StructureSystem
(
args
)
def
handleOpenFileSignal
(
self
):
def
handleOpenFileSignal
(
self
):
'''
'''
可以多选图像文件
可以多选图像文件
'''
'''
selectedFiles
=
QFileDialog
.
getOpenFileNames
(
self
,
selectedFiles
=
QFileDialog
.
getOpenFileNames
(
"多文件选择"
,
"/"
,
"图片文件 (*.png *.jpeg *.jpg *.bmp *.pdf)"
)[
0
]
self
,
"多文件选择"
,
"/"
,
"图片文件 (*.png *.jpeg *.jpg *.bmp *.pdf)"
)[
0
]
if
len
(
selectedFiles
)
>
0
:
if
len
(
selectedFiles
)
>
0
:
self
.
imagePaths
=
selectedFiles
self
.
imagePaths
=
selectedFiles
self
.
screenShot
=
None
# discard screenshot temp image
self
.
screenShot
=
None
# discard screenshot temp image
self
.
pb
.
setValue
(
0
)
self
.
pb
.
setValue
(
0
)
# def screenShotSlot(self):
# def screenShotSlot(self):
...
@@ -415,18 +437,19 @@ class APP_Image2Doc(QWidget):
...
@@ -415,18 +437,19 @@ class APP_Image2Doc(QWidget):
# self.pb.setValue(0)
# self.pb.setValue(0)
def
handleStartSignal
(
self
,
lang
=
'EN'
,
pdfParser
=
False
):
def
handleStartSignal
(
self
,
lang
=
'EN'
,
pdfParser
=
False
):
if
self
.
screenShot
:
# for screenShot
if
self
.
screenShot
:
# for screenShot
img_name
=
'screenshot_'
+
time
.
strftime
(
"%Y%m%d%H%M%S"
,
time
.
localtime
())
img_name
=
'screenshot_'
+
time
.
strftime
(
"%Y%m%d%H%M%S"
,
time
.
localtime
())
image
=
QImageToCvMat
(
self
.
screenShot
)
image
=
QImageToCvMat
(
self
.
screenShot
)
self
.
predictAndSave
(
image
,
img_name
,
lang
)
self
.
predictAndSave
(
image
,
img_name
,
lang
)
# update Progress Bar
# update Progress Bar
self
.
pb
.
setValue
(
1
)
self
.
pb
.
setValue
(
1
)
QMessageBox
.
information
(
self
,
QMessageBox
.
information
(
self
,
u
'Information'
,
"文档提取完成"
)
u
'Information'
,
"文档提取完成"
)
elif
len
(
self
.
imagePaths
)
>
0
:
# for image file selection
elif
len
(
self
.
imagePaths
)
>
0
:
# for image file selection
# Must set image path list and language before start
# Must set image path list and language before start
self
.
output_dir
=
os
.
path
.
join
(
self
.
output_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
self
.
imagePaths
[
0
]),
"output"
)
# output_dir shold be same as imagepath
os
.
path
.
dirname
(
self
.
imagePaths
[
0
]),
"output"
)
# output_dir shold be same as imagepath
self
.
_thread
.
setOutputDir
(
self
.
output_dir
)
self
.
_thread
.
setOutputDir
(
self
.
output_dir
)
self
.
_thread
.
setImagePath
(
self
.
imagePaths
)
self
.
_thread
.
setImagePath
(
self
.
imagePaths
)
self
.
_thread
.
setLang
(
lang
)
self
.
_thread
.
setLang
(
lang
)
...
@@ -438,12 +461,10 @@ class APP_Image2Doc(QWidget):
...
@@ -438,12 +461,10 @@ class APP_Image2Doc(QWidget):
self
.
PDFParserButton
.
setEnabled
(
False
)
self
.
PDFParserButton
.
setEnabled
(
False
)
# 启动工作进程
# 启动工作进程
self
.
_thread
.
start
()
self
.
_thread
.
start
()
self
.
time_start
=
time
.
time
()
# log start time
self
.
time_start
=
time
.
time
()
# log start time
QMessageBox
.
information
(
self
,
QMessageBox
.
information
(
self
,
u
'Information'
,
"开始转换"
)
u
'Information'
,
"开始转换"
)
else
:
else
:
QMessageBox
.
warning
(
self
,
QMessageBox
.
warning
(
self
,
u
'Information'
,
"请选择要识别的文件或截图"
)
u
'Information'
,
"请选择要识别的文件或截图"
)
def
handleShowResultSignal
(
self
):
def
handleShowResultSignal
(
self
):
if
self
.
output_dir
is
None
:
if
self
.
output_dir
is
None
:
...
@@ -454,15 +475,16 @@ class APP_Image2Doc(QWidget):
...
@@ -454,15 +475,16 @@ class APP_Image2Doc(QWidget):
else
:
else
:
os
.
system
(
'open '
+
os
.
path
.
normpath
(
self
.
output_dir
))
os
.
system
(
'open '
+
os
.
path
.
normpath
(
self
.
output_dir
))
else
:
else
:
QMessageBox
.
information
(
self
,
QMessageBox
.
information
(
self
,
u
'Information'
,
"输出文件不存在"
)
u
'Information'
,
"输出文件不存在"
)
def
handleProgressBarUpdateSingal
(
self
,
i
):
def
handleProgressBarUpdateSingal
(
self
,
i
):
self
.
pb
.
setValue
(
i
)
self
.
pb
.
setValue
(
i
)
# calculate time left of recognition
# calculate time left of recognition
lenbar
=
self
.
pb
.
maximum
()
lenbar
=
self
.
pb
.
maximum
()
avg_time
=
(
time
.
time
()
-
self
.
time_start
)
/
i
# Use average time to prevent time fluctuations
avg_time
=
(
time
.
time
()
-
self
.
time_start
time_left
=
str
(
datetime
.
timedelta
(
seconds
=
avg_time
*
(
lenbar
-
i
))).
split
(
"."
)[
0
]
# Remove microseconds
)
/
i
# Use average time to prevent time fluctuations
time_left
=
str
(
datetime
.
timedelta
(
seconds
=
avg_time
*
(
lenbar
-
i
))).
split
(
"."
)[
0
]
# Remove microseconds
self
.
timeEstLabel
.
setText
(
f
"Time Left:
{
time_left
}
"
)
# show time left
self
.
timeEstLabel
.
setText
(
f
"Time Left:
{
time_left
}
"
)
# show time left
def
handleProgressBarRangeSingal
(
self
,
max
):
def
handleProgressBarRangeSingal
(
self
,
max
):
...
...
ppstructure/recovery/requirements.txt
浏览文件 @
cad701d4
...
@@ -2,4 +2,5 @@ python-docx
...
@@ -2,4 +2,5 @@ python-docx
PyMuPDF==1.19.0
PyMuPDF==1.19.0
beautifulsoup4
beautifulsoup4
fonttools>=4.24.0
fonttools>=4.24.0
fire>=0.3.0
fire>=0.3.0
\ No newline at end of file
pdf2docx
\ No newline at end of file
ppstructure/table/predict_table.py
浏览文件 @
cad701d4
...
@@ -60,12 +60,16 @@ class TableSystem(object):
...
@@ -60,12 +60,16 @@ class TableSystem(object):
self
.
args
=
args
self
.
args
=
args
if
not
args
.
show_log
:
if
not
args
.
show_log
:
logger
.
setLevel
(
logging
.
INFO
)
logger
.
setLevel
(
logging
.
INFO
)
args
.
benchmark
=
False
benchmark_tmp
=
False
if
args
.
benchmark
:
benchmark_tmp
=
args
.
benchmark
args
.
benchmark
=
False
self
.
text_detector
=
predict_det
.
TextDetector
(
copy
.
deepcopy
(
self
.
text_detector
=
predict_det
.
TextDetector
(
copy
.
deepcopy
(
args
))
if
text_detector
is
None
else
text_detector
args
))
if
text_detector
is
None
else
text_detector
self
.
text_recognizer
=
predict_rec
.
TextRecognizer
(
copy
.
deepcopy
(
self
.
text_recognizer
=
predict_rec
.
TextRecognizer
(
copy
.
deepcopy
(
args
))
if
text_recognizer
is
None
else
text_recognizer
args
))
if
text_recognizer
is
None
else
text_recognizer
args
.
benchmark
=
True
if
benchmark_tmp
:
args
.
benchmark
=
True
self
.
table_structurer
=
predict_strture
.
TableStructurer
(
args
)
self
.
table_structurer
=
predict_strture
.
TableStructurer
(
args
)
if
args
.
table_algorithm
in
[
'TableMaster'
]:
if
args
.
table_algorithm
in
[
'TableMaster'
]:
self
.
match
=
TableMasterMatcher
()
self
.
match
=
TableMasterMatcher
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录