Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
d27360a9
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看板
提交
d27360a9
编写于
6月 08, 2021
作者:
W
WenmuZhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move draw_result to utilitu.py
上级
dec76eb7
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
33 addition
and
28 deletion
+33
-28
ppstructure/paddlestructure.py
ppstructure/paddlestructure.py
+7
-24
ppstructure/predict_system.py
ppstructure/predict_system.py
+5
-2
ppstructure/utility.py
ppstructure/utility.py
+21
-2
未找到文件。
ppstructure/paddlestructure.py
浏览文件 @
d27360a9
...
...
@@ -25,27 +25,23 @@ from pathlib import Path
from
ppocr.utils.logging
import
get_logger
from
ppstructure.predict_system
import
OCRSystem
,
save_res
from
utility
import
init_args
from
ppstructure.table.predict_table
import
to_excel
from
ppstructure.utility
import
init_args
,
draw_result
logger
=
get_logger
()
from
ppocr.utils.utility
import
check_and_read_gif
,
get_image_file_list
from
ppocr.utils.network
import
maybe_download
,
download_with_progressbar
__all__
=
[
'PaddleStructure'
]
__all__
=
[
'PaddleStructure'
,
'draw_result'
,
'to_excel'
]
VERSION
=
'2.1'
BASE_DIR
=
os
.
path
.
expanduser
(
"~/.paddlestructure/"
)
model_urls
=
{
'det'
:
{
'https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar'
,
},
'rec'
:
{
'https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar'
,
},
'structure'
:
{
'https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar'
,
},
'det'
:
'https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_det_infer.tar'
,
'rec'
:
'https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_rec_infer.tar'
,
'structure'
:
'https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_structure_infer.tar'
}
...
...
@@ -143,21 +139,8 @@ def main():
img_name
=
os
.
path
.
basename
(
img_path
).
split
(
'.'
)[
0
]
logger
.
info
(
'{}{}{}'
.
format
(
'*'
*
10
,
img_path
,
'*'
*
10
))
result
=
structure_engine
(
img_path
)
save_res
(
result
,
args
.
output
,
os
.
path
.
basename
(
img_path
).
split
(
'.'
)[
0
])
for
item
in
result
:
logger
.
info
(
item
[
'res'
])
save_res
(
result
,
save_folder
,
img_name
)
logger
.
info
(
'result save to {}'
.
format
(
os
.
path
.
join
(
save_folder
,
img_name
)))
if
__name__
==
'__main__'
:
table_engine
=
PaddleStructure
(
det_model_dir
=
'/Users/zhoujun20/Desktop/工作相关/table/table_pr/PaddleOCR/inference/table/ch_ppocr_mobile_v2.0_table_det_infer'
,
rec_model_dir
=
'/Users/zhoujun20/Desktop/工作相关/table/table_pr/PaddleOCR/inference/table/ch_ppocr_mobile_v2.0_table_rec_infer'
,
structure_model_dir
=
'/Users/zhoujun20/Desktop/工作相关/table/table_pr/PaddleOCR/inference/table/ch_ppocr_mobile_v2.0_table_structure_infer'
,
output
=
'/Users/zhoujun20/Desktop/工作相关/table/table_pr/PaddleOCR/output/table'
,
show_log
=
True
)
img
=
cv2
.
imread
(
'/Users/zhoujun20/Desktop/工作相关/table/table_pr/PaddleOCR/ppstructure/test_imgs/table_1.png'
)
result
=
table_engine
(
img
)
for
line
in
result
:
print
(
line
)
ppstructure/predict_system.py
浏览文件 @
d27360a9
...
...
@@ -31,7 +31,7 @@ from ppocr.utils.utility import get_image_file_list, check_and_read_gif
from
ppocr.utils.logging
import
get_logger
from
tools.infer.predict_system
import
TextSystem
from
ppstructure.table.predict_table
import
TableSystem
,
to_excel
from
ppstructure.utility
import
parse_args
from
ppstructure.utility
import
parse_args
,
draw_result
logger
=
get_logger
()
...
...
@@ -39,7 +39,8 @@ logger = get_logger()
class
OCRSystem
(
object
):
def
__init__
(
self
,
args
):
args
.
det_pad
=
True
args
.
det_pad_size
=
640
args
.
det_pad_size
=
960
args
.
drop_score
=
0
self
.
text_system
=
TextSystem
(
args
)
self
.
table_system
=
TableSystem
(
args
,
self
.
text_system
.
text_detector
,
self
.
text_system
.
text_recognizer
)
self
.
table_layout
=
lp
.
PaddleDetectionLayoutModel
(
"lp://PubLayNet/ppyolov2_r50vd_dcn_365e_publaynet/config"
,
...
...
@@ -107,6 +108,8 @@ def main(args):
starttime
=
time
.
time
()
res
=
structure_sys
(
img
)
save_res
(
res
,
save_folder
,
img_name
)
draw_img
=
draw_result
(
img
,
res
,
args
.
vis_font_path
)
cv2
.
imwrite
(
os
.
path
.
join
(
save_folder
,
img_name
,
'show.jpg'
),
draw_img
)
logger
.
info
(
'result save to {}'
.
format
(
os
.
path
.
join
(
save_folder
,
img_name
)))
elapse
=
time
.
time
()
-
starttime
logger
.
info
(
"Predict time : {:.3f}s"
.
format
(
elapse
))
...
...
ppstructure/utility.py
浏览文件 @
d27360a9
...
...
@@ -11,9 +11,10 @@
# 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
logging
from
tools.infer.utility
import
str2bool
,
init_args
as
infer_args
from
PIL
import
Image
import
numpy
as
np
from
tools.infer.utility
import
draw_ocr_box_txt
,
init_args
as
infer_args
def
init_args
():
...
...
@@ -38,3 +39,21 @@ def init_args():
def
parse_args
():
parser
=
init_args
()
return
parser
.
parse_args
()
def
draw_result
(
image
,
result
,
font_path
):
if
isinstance
(
image
,
np
.
ndarray
):
image
=
Image
.
fromarray
(
image
)
boxes
,
txts
,
scores
=
[],
[],
[]
for
region
in
result
:
if
region
[
'type'
]
==
'Table'
:
pass
elif
region
[
'type'
]
==
'Figure'
:
pass
else
:
for
box
,
rec_res
in
zip
(
region
[
'res'
][
0
],
region
[
'res'
][
1
]):
boxes
.
append
(
np
.
array
(
box
).
reshape
(
-
1
,
2
))
txts
.
append
(
rec_res
[
0
])
scores
.
append
(
rec_res
[
1
])
im_show
=
draw_ocr_box_txt
(
image
,
boxes
,
txts
,
scores
,
font_path
=
font_path
,
drop_score
=
0
)
return
im_show
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录