Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
60ec9546
P
PaddleOCR
项目概览
s920243400
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
60ec9546
编写于
7月 28, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
read gif read func
上级
301aac1c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
47 addition
and
20 deletion
+47
-20
ppocr/data/det/db_process.py
ppocr/data/det/db_process.py
+4
-2
ppocr/utils/utility.py
ppocr/utils/utility.py
+15
-1
tools/infer/predict_det.py
tools/infer/predict_det.py
+4
-2
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+4
-2
tools/infer/predict_system.py
tools/infer/predict_system.py
+20
-13
未找到文件。
ppocr/data/det/db_process.py
浏览文件 @
60ec9546
...
@@ -17,7 +17,7 @@ import cv2
...
@@ -17,7 +17,7 @@ import cv2
import
numpy
as
np
import
numpy
as
np
import
json
import
json
import
sys
import
sys
from
ppocr.utils.utility
import
initial_logger
from
ppocr.utils.utility
import
initial_logger
,
check_and_read_gif
logger
=
initial_logger
()
logger
=
initial_logger
()
from
.data_augment
import
AugmentData
from
.data_augment
import
AugmentData
...
@@ -100,6 +100,8 @@ class DBProcessTrain(object):
...
@@ -100,6 +100,8 @@ class DBProcessTrain(object):
def
__call__
(
self
,
label_infor
):
def
__call__
(
self
,
label_infor
):
img_path
,
gt_label
=
self
.
convert_label_infor
(
label_infor
)
img_path
,
gt_label
=
self
.
convert_label_infor
(
label_infor
)
imgvalue
,
flag
=
check_and_read_gif
(
img_path
)
if
not
flag
:
imgvalue
=
cv2
.
imread
(
img_path
)
imgvalue
=
cv2
.
imread
(
img_path
)
if
imgvalue
is
None
:
if
imgvalue
is
None
:
logger
.
info
(
"{} does not exist!"
.
format
(
img_path
))
logger
.
info
(
"{} does not exist!"
.
format
(
img_path
))
...
...
ppocr/utils/utility.py
浏览文件 @
60ec9546
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
logging
import
logging
import
os
import
os
import
imghdr
import
imghdr
import
cv2
def
initial_logger
():
def
initial_logger
():
...
@@ -62,7 +63,7 @@ def get_image_file_list(img_file):
...
@@ -62,7 +63,7 @@ def get_image_file_list(img_file):
if
img_file
is
None
or
not
os
.
path
.
exists
(
img_file
):
if
img_file
is
None
or
not
os
.
path
.
exists
(
img_file
):
raise
Exception
(
"not found any img file in {}"
.
format
(
img_file
))
raise
Exception
(
"not found any img file in {}"
.
format
(
img_file
))
img_end
=
{
'jpg'
,
'bmp'
,
'png'
,
'jpeg'
,
'rgb'
,
'tif'
,
'tiff'
}
img_end
=
{
'jpg'
,
'bmp'
,
'png'
,
'jpeg'
,
'rgb'
,
'tif'
,
'tiff'
,
'gif'
,
'GIF'
}
if
os
.
path
.
isfile
(
img_file
)
and
imghdr
.
what
(
img_file
)
in
img_end
:
if
os
.
path
.
isfile
(
img_file
)
and
imghdr
.
what
(
img_file
)
in
img_end
:
imgs_lists
.
append
(
img_file
)
imgs_lists
.
append
(
img_file
)
elif
os
.
path
.
isdir
(
img_file
):
elif
os
.
path
.
isdir
(
img_file
):
...
@@ -75,6 +76,19 @@ def get_image_file_list(img_file):
...
@@ -75,6 +76,19 @@ def get_image_file_list(img_file):
return
imgs_lists
return
imgs_lists
def
check_and_read_gif
(
img_path
):
if
os
.
path
.
basename
(
img_path
)[
-
3
:]
in
[
'gif'
,
'GIF'
]:
gif
=
cv2
.
VideoCapture
(
img_path
)
ret
,
frame
=
gif
.
read
()
if
not
ret
:
logging
.
info
(
"Cannot read {}. This gif image maybe corrupted."
)
if
len
(
frame
.
shape
)
==
2
or
frame
.
shape
[
-
1
]
==
1
:
frame
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_GRAY2RGB
)
imgvalue
=
frame
[:,
:,
::
-
1
]
return
imgvalue
,
True
return
None
,
False
from
paddle
import
fluid
from
paddle
import
fluid
...
...
tools/infer/predict_det.py
浏览文件 @
60ec9546
...
@@ -20,7 +20,7 @@ sys.path.append(os.path.join(__dir__, '../..'))
...
@@ -20,7 +20,7 @@ sys.path.append(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
logger
=
initial_logger
()
logger
=
initial_logger
()
from
ppocr.utils.utility
import
get_image_file_list
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
import
cv2
import
cv2
from
ppocr.data.det.east_process
import
EASTProcessTest
from
ppocr.data.det.east_process
import
EASTProcessTest
from
ppocr.data.det.db_process
import
DBProcessTest
from
ppocr.data.det.db_process
import
DBProcessTest
...
@@ -139,6 +139,8 @@ if __name__ == "__main__":
...
@@ -139,6 +139,8 @@ if __name__ == "__main__":
if
not
os
.
path
.
exists
(
draw_img_save
):
if
not
os
.
path
.
exists
(
draw_img_save
):
os
.
makedirs
(
draw_img_save
)
os
.
makedirs
(
draw_img_save
)
for
image_file
in
image_file_list
:
for
image_file
in
image_file_list
:
img
,
flag
=
check_and_read_gif
(
image_file
)
if
not
flag
:
img
=
cv2
.
imread
(
image_file
)
img
=
cv2
.
imread
(
image_file
)
if
img
is
None
:
if
img
is
None
:
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
...
...
tools/infer/predict_rec.py
浏览文件 @
60ec9546
...
@@ -20,7 +20,7 @@ sys.path.append(os.path.abspath(os.path.join(__dir__, '../..')))
...
@@ -20,7 +20,7 @@ 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
logger
=
initial_logger
()
logger
=
initial_logger
()
from
ppocr.utils.utility
import
get_image_file_list
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
import
cv2
import
cv2
import
copy
import
copy
import
numpy
as
np
import
numpy
as
np
...
@@ -153,7 +153,9 @@ def main(args):
...
@@ -153,7 +153,9 @@ def main(args):
valid_image_file_list
=
[]
valid_image_file_list
=
[]
img_list
=
[]
img_list
=
[]
for
image_file
in
image_file_list
:
for
image_file
in
image_file_list
:
img
=
cv2
.
imread
(
image_file
,
cv2
.
IMREAD_COLOR
)
img
,
flag
=
check_and_read_gif
(
image_file
)
if
not
flag
:
img
=
cv2
.
imread
(
image_file
)
if
img
is
None
:
if
img
is
None
:
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
continue
continue
...
...
tools/infer/predict_system.py
浏览文件 @
60ec9546
...
@@ -27,7 +27,7 @@ import copy
...
@@ -27,7 +27,7 @@ import copy
import
numpy
as
np
import
numpy
as
np
import
math
import
math
import
time
import
time
from
ppocr.utils.utility
import
get_image_file_list
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
from
PIL
import
Image
from
PIL
import
Image
from
tools.infer.utility
import
draw_ocr
from
tools.infer.utility
import
draw_ocr
from
tools.infer.utility
import
draw_ocr_box_txt
from
tools.infer.utility
import
draw_ocr_box_txt
...
@@ -49,16 +49,21 @@ class TextSystem(object):
...
@@ -49,16 +49,21 @@ class TextSystem(object):
points[:, 0] = points[:, 0] - left
points[:, 0] = points[:, 0] - left
points[:, 1] = points[:, 1] - top
points[:, 1] = points[:, 1] - top
'''
'''
img_crop_width
=
int
(
max
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
1
]),
img_crop_width
=
int
(
max
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
1
]),
np
.
linalg
.
norm
(
points
[
2
]
-
points
[
3
])))
np
.
linalg
.
norm
(
points
[
2
]
-
points
[
3
])))
img_crop_height
=
int
(
max
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
3
]),
img_crop_height
=
int
(
max
(
np
.
linalg
.
norm
(
points
[
0
]
-
points
[
3
]),
np
.
linalg
.
norm
(
points
[
1
]
-
points
[
2
])))
np
.
linalg
.
norm
(
points
[
1
]
-
points
[
2
])))
pts_std
=
np
.
float32
([[
0
,
0
],
pts_std
=
np
.
float32
([[
0
,
0
],
[
img_crop_width
,
0
],
[
img_crop_width
,
0
],
[
img_crop_width
,
img_crop_height
],
[
img_crop_width
,
img_crop_height
],
[
0
,
img_crop_height
]])
[
0
,
img_crop_height
]])
M
=
cv2
.
getPerspectiveTransform
(
points
,
pts_std
)
M
=
cv2
.
getPerspectiveTransform
(
points
,
pts_std
)
dst_img
=
cv2
.
warpPerspective
(
img
,
M
,
(
img_crop_width
,
img_crop_height
),
dst_img
=
cv2
.
warpPerspective
(
img
,
M
,
(
img_crop_width
,
img_crop_height
),
borderMode
=
cv2
.
BORDER_REPLICATE
,
borderMode
=
cv2
.
BORDER_REPLICATE
,
flags
=
cv2
.
INTER_CUBIC
)
flags
=
cv2
.
INTER_CUBIC
)
dst_img_height
,
dst_img_width
=
dst_img
.
shape
[
0
:
2
]
dst_img_height
,
dst_img_width
=
dst_img
.
shape
[
0
:
2
]
...
@@ -119,6 +124,8 @@ def main(args):
...
@@ -119,6 +124,8 @@ def main(args):
is_visualize
=
True
is_visualize
=
True
tackle_img_num
=
0
tackle_img_num
=
0
for
image_file
in
image_file_list
:
for
image_file
in
image_file_list
:
img
,
flag
=
check_and_read_gif
(
image_file
)
if
not
flag
:
img
=
cv2
.
imread
(
image_file
)
img
=
cv2
.
imread
(
image_file
)
if
img
is
None
:
if
img
is
None
:
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录