Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
ef156b19
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1525
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ef156b19
编写于
6月 20, 2020
作者:
张欣-男
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化tools/infer/predict_system.py代码
上级
a28ef7f0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
12 deletion
+20
-12
tools/infer/predict_system.py
tools/infer/predict_system.py
+20
-12
未找到文件。
tools/infer/predict_system.py
浏览文件 @
ef156b19
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
# limitations under the License.
# limitations under the License.
import
os
import
os
import
sys
import
sys
__dir__
=
os
.
path
.
dirname
(
__file__
)
__dir__
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)
)
sys
.
path
.
append
(
__dir__
)
sys
.
path
.
append
(
__dir__
)
sys
.
path
.
append
(
os
.
path
.
join
(
__dir__
,
'../..'
))
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
__dir__
,
'../..'
)
))
import
tools.infer.utility
as
utility
import
tools.infer.utility
as
utility
from
ppocr.utils.utility
import
initial_logger
from
ppocr.utils.utility
import
initial_logger
...
@@ -39,6 +39,7 @@ class TextSystem(object):
...
@@ -39,6 +39,7 @@ class TextSystem(object):
self
.
text_recognizer
=
predict_rec
.
TextRecognizer
(
args
)
self
.
text_recognizer
=
predict_rec
.
TextRecognizer
(
args
)
def
get_rotate_crop_image
(
self
,
img
,
points
):
def
get_rotate_crop_image
(
self
,
img
,
points
):
'''
img_height, img_width = img.shape[0:2]
img_height, img_width = img.shape[0:2]
left = int(np.min(points[:, 0]))
left = int(np.min(points[:, 0]))
right = int(np.max(points[:, 0]))
right = int(np.max(points[:, 0]))
...
@@ -47,15 +48,19 @@ class TextSystem(object):
...
@@ -47,15 +48,19 @@ class TextSystem(object):
img_crop = img[top:bottom, left:right, :].copy()
img_crop = img[top:bottom, left:right, :].copy()
points[:, 0] = points[:, 0] - left
points[:, 0] = points[:, 0] - left
points[:, 1] = points[:, 1] - top
points[:, 1] = points[:, 1] - top
img_crop_width
=
int
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
1
]))
'''
img_crop_height
=
int
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
3
]))
img_crop_width
=
int
(
max
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
1
]),
pts_std
=
np
.
float32
([[
0
,
0
],
[
img_crop_width
,
0
],
\
np
.
linalg
.
norm
(
points
[
2
]
-
points
[
3
])))
[
img_crop_width
,
img_crop_height
],
[
0
,
img_crop_height
]])
img_crop_height
=
int
(
max
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
3
]),
np
.
linalg
.
norm
(
points
[
1
]
-
points
[
2
])))
pts_std
=
np
.
float32
([[
0
,
0
],
[
img_crop_width
,
0
],
[
img_crop_width
,
img_crop_height
],
[
0
,
img_crop_height
]])
M
=
cv2
.
getPerspectiveTransform
(
points
,
pts_std
)
M
=
cv2
.
getPerspectiveTransform
(
points
,
pts_std
)
dst_img
=
cv2
.
warpPerspective
(
dst_img
=
cv2
.
warpPerspective
(
img
,
M
,
(
img_crop_width
,
img_crop_height
),
img_crop
,
borderMode
=
cv2
.
BORDER_REPLICATE
,
M
,
(
img_crop_width
,
img_crop_height
),
flags
=
cv2
.
INTER_CUBIC
)
borderMode
=
cv2
.
BORDER_REPLICATE
)
dst_img_height
,
dst_img_width
=
dst_img
.
shape
[
0
:
2
]
dst_img_height
,
dst_img_width
=
dst_img
.
shape
[
0
:
2
]
if
dst_img_height
*
1.0
/
dst_img_width
>=
1.5
:
if
dst_img_height
*
1.0
/
dst_img_width
>=
1.5
:
dst_img
=
np
.
rot90
(
dst_img
)
dst_img
=
np
.
rot90
(
dst_img
)
...
@@ -106,8 +111,7 @@ def sorted_boxes(dt_boxes):
...
@@ -106,8 +111,7 @@ def sorted_boxes(dt_boxes):
return
_boxes
return
_boxes
if
__name__
==
"__main__"
:
def
main
(
args
):
args
=
utility
.
parse_args
()
image_file_list
=
get_image_file_list
(
args
.
image_dir
)
image_file_list
=
get_image_file_list
(
args
.
image_dir
)
text_sys
=
TextSystem
(
args
)
text_sys
=
TextSystem
(
args
)
is_visualize
=
True
is_visualize
=
True
...
@@ -145,3 +149,7 @@ if __name__ == "__main__":
...
@@ -145,3 +149,7 @@ if __name__ == "__main__":
draw_img
[:,
:,
::
-
1
])
draw_img
[:,
:,
::
-
1
])
print
(
"The visualized image saved in {}"
.
format
(
print
(
"The visualized image saved in {}"
.
format
(
os
.
path
.
join
(
draw_img_save
,
os
.
path
.
basename
(
image_file
))))
os
.
path
.
join
(
draw_img_save
,
os
.
path
.
basename
(
image_file
))))
if
__name__
==
"__main__"
:
main
(
utility
.
parse_args
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录