Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
283be69c
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 2 年 前同步成功
通知
285
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
283be69c
编写于
12月 29, 2022
作者:
jm_12138
提交者:
GitHub
12月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update ch_pp-ocrv3 (#2174)
上级
4382eee6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
75 addition
and
40 deletion
+75
-40
modules/image/text_recognition/ch_pp-ocrv3/README.md
modules/image/text_recognition/ch_pp-ocrv3/README.md
+8
-1
modules/image/text_recognition/ch_pp-ocrv3/module.py
modules/image/text_recognition/ch_pp-ocrv3/module.py
+25
-2
modules/image/text_recognition/ch_pp-ocrv3/requirements.txt
modules/image/text_recognition/ch_pp-ocrv3/requirements.txt
+0
-2
modules/image/text_recognition/ch_pp-ocrv3/test.py
modules/image/text_recognition/ch_pp-ocrv3/test.py
+28
-35
modules/image/text_recognition/ch_pp-ocrv3/utils.py
modules/image/text_recognition/ch_pp-ocrv3/utils.py
+14
-0
未找到文件。
modules/image/text_recognition/ch_pp-ocrv3/README.md
浏览文件 @
283be69c
...
@@ -163,6 +163,9 @@
...
@@ -163,6 +163,9 @@
print(r.json()["results"])
print(r.json()["results"])
```
```
-
### Gradio App 支持
从 PaddleHub 2.3.1 开始支持使用链接 http://127.0.0.1:8866/gradio/ch_pp-ocrv3 在浏览器中访问 ch_pp-ocrv3 的 Gradio App。
## 五、更新历史
## 五、更新历史
*
1.0.0
*
1.0.0
...
@@ -173,6 +176,10 @@
...
@@ -173,6 +176,10 @@
移除 Fluid API
移除 Fluid API
*
1.2.0
添加 Gradio APP 支持
-
```shell
-
```shell
$ hub install ch_pp-ocrv3==1.
1
.0
$ hub install ch_pp-ocrv3==1.
2
.0
```
```
modules/image/text_recognition/ch_pp-ocrv3/module.py
浏览文件 @
283be69c
...
@@ -31,21 +31,22 @@ from .utils import base64_to_cv2
...
@@ -31,21 +31,22 @@ from .utils import base64_to_cv2
from
.utils
import
draw_ocr
from
.utils
import
draw_ocr
from
.utils
import
get_image_ext
from
.utils
import
get_image_ext
from
.utils
import
sorted_boxes
from
.utils
import
sorted_boxes
from
paddlehub.utils.utils
import
logger
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
serving
from
paddlehub.module.module
import
serving
from
paddlehub.utils.utils
import
logger
@
moduleinfo
(
@
moduleinfo
(
name
=
"ch_pp-ocrv3"
,
name
=
"ch_pp-ocrv3"
,
version
=
"1.
1
.0"
,
version
=
"1.
2
.0"
,
summary
=
"The module can recognize the chinese texts in an image. Firstly, it will detect the text box positions
\
summary
=
"The module can recognize the chinese texts in an image. Firstly, it will detect the text box positions
\
based on the differentiable_binarization_chn module. Then it classifies the text angle and recognizes the chinese texts. "
,
based on the differentiable_binarization_chn module. Then it classifies the text angle and recognizes the chinese texts. "
,
author
=
"paddle-dev"
,
author
=
"paddle-dev"
,
author_email
=
"paddle-dev@baidu.com"
,
author_email
=
"paddle-dev@baidu.com"
,
type
=
"cv/text_recognition"
)
type
=
"cv/text_recognition"
)
class
ChPPOCRv3
:
class
ChPPOCRv3
:
def
__init__
(
self
,
text_detector_module
=
None
,
enable_mkldnn
=
False
):
def
__init__
(
self
,
text_detector_module
=
None
,
enable_mkldnn
=
False
):
"""
"""
initialize with the necessary elements
initialize with the necessary elements
...
@@ -477,3 +478,25 @@ class ChPPOCRv3:
...
@@ -477,3 +478,25 @@ class ChPPOCRv3:
Add the command input options
Add the command input options
"""
"""
self
.
arg_input_group
.
add_argument
(
'--input_path'
,
type
=
str
,
default
=
None
,
help
=
"diretory to image"
)
self
.
arg_input_group
.
add_argument
(
'--input_path'
,
type
=
str
,
default
=
None
,
help
=
"diretory to image"
)
def
create_gradio_app
(
self
):
import
gradio
as
gr
def
inference
(
image
,
use_gpu
=
False
,
box_thresh
=
0.5
,
text_thresh
=
0.5
,
angle_classification_thresh
=
0.9
):
return
self
.
recognize_text
(
paths
=
[
image
],
use_gpu
=
use_gpu
,
output_dir
=
None
,
visualization
=
False
,
box_thresh
=
box_thresh
,
text_thresh
=
text_thresh
,
angle_classification_thresh
=
angle_classification_thresh
)
return
gr
.
Interface
(
inference
,
[
gr
.
Image
(
type
=
'filepath'
),
gr
.
Checkbox
(),
gr
.
Slider
(
0
,
1.0
,
0.5
,
step
=
0.01
),
gr
.
Slider
(
0
,
1.0
,
0.5
,
step
=
0.01
),
gr
.
Slider
(
0
,
1.0
,
0.5
,
step
=
0.01
)
],
[
gr
.
JSON
(
label
=
'results'
)],
title
=
'ch_pp-ocrv3'
,
allow_flagging
=
False
)
modules/image/text_recognition/ch_pp-ocrv3/requirements.txt
已删除
100644 → 0
浏览文件 @
4382eee6
shapely
pyclipper
modules/image/text_recognition/ch_pp-ocrv3/test.py
浏览文件 @
283be69c
...
@@ -4,13 +4,14 @@ import unittest
...
@@ -4,13 +4,14 @@ import unittest
import
cv2
import
cv2
import
requests
import
requests
import
paddlehub
as
hub
import
paddlehub
as
hub
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
class
TestHubModule
(
unittest
.
TestCase
):
class
TestHubModule
(
unittest
.
TestCase
):
@
classmethod
@
classmethod
def
setUpClass
(
cls
)
->
None
:
def
setUpClass
(
cls
)
->
None
:
img_url
=
'https://unsplash.com/photos/KTzZVDjUsXw/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8MzM3fHx0ZXh0fGVufDB8fHx8MTY2MzUxMTExMQ&force=true&w=640'
img_url
=
'https://unsplash.com/photos/KTzZVDjUsXw/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8MzM3fHx0ZXh0fGVufDB8fHx8MTY2MzUxMTExMQ&force=true&w=640'
...
@@ -34,13 +35,13 @@ class TestHubModule(unittest.TestCase):
...
@@ -34,13 +35,13 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
False
,
use_gpu
=
False
,
visualization
=
False
,
visualization
=
False
,
)
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[
self
.
assertEqual
(
results
[
0
][
'data'
],
[
{
{
'text'
:
'GIVE.'
,
'
text'
:
'GIVE.'
,
'confidence'
:
0.9509806632995605
,
'
confidence'
:
0.9509768486022949
,
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
},
},
{
{
'text'
:
'THANKS'
,
'
text'
:
'THANKS'
,
'confidence'
:
0.9943129420280457
,
'
confidence'
:
0.9943074584007263
,
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
}])
}])
...
@@ -50,13 +51,13 @@ class TestHubModule(unittest.TestCase):
...
@@ -50,13 +51,13 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
False
,
use_gpu
=
False
,
visualization
=
False
,
visualization
=
False
,
)
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[
self
.
assertEqual
(
results
[
0
][
'data'
],
[
{
{
'text'
:
'GIVE.'
,
'
text'
:
'GIVE.'
,
'confidence'
:
0.9509806632995605
,
'
confidence'
:
0.9509768486022949
,
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
},
},
{
{
'text'
:
'THANKS'
,
'
text'
:
'THANKS'
,
'confidence'
:
0.9943129420280457
,
'
confidence'
:
0.9943074584007263
,
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
}])
}])
...
@@ -66,13 +67,13 @@ class TestHubModule(unittest.TestCase):
...
@@ -66,13 +67,13 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
True
,
use_gpu
=
True
,
visualization
=
False
,
visualization
=
False
,
)
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[
self
.
assertEqual
(
results
[
0
][
'data'
],
[
{
{
'text'
:
'GIVE.'
,
'
text'
:
'GIVE.'
,
'confidence'
:
0.9509806632995605
,
'
confidence'
:
0.9509768486022949
,
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
},
},
{
{
'text'
:
'THANKS'
,
'
text'
:
'THANKS'
,
'confidence'
:
0.9943129420280457
,
'
confidence'
:
0.9943074584007263
,
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
}])
}])
...
@@ -82,29 +83,21 @@ class TestHubModule(unittest.TestCase):
...
@@ -82,29 +83,21 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
False
,
use_gpu
=
False
,
visualization
=
True
,
visualization
=
True
,
)
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[
self
.
assertEqual
(
results
[
0
][
'data'
],
[
{
{
'text'
:
'GIVE.'
,
'
text'
:
'GIVE.'
,
'confidence'
:
0.9509806632995605
,
'
confidence'
:
0.9509768486022949
,
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
'text_box_position'
:
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]
},
},
{
{
'text'
:
'THANKS'
,
'
text'
:
'THANKS'
,
'confidence'
:
0.9943129420280457
,
'
confidence'
:
0.9943074584007263
,
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
'text_box_position'
:
[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]]
}])
}])
def
test_recognize_text5
(
self
):
def
test_recognize_text5
(
self
):
self
.
assertRaises
(
self
.
assertRaises
(
AttributeError
,
self
.
module
.
recognize_text
,
images
=
[
'tests/test.jpg'
])
AttributeError
,
self
.
module
.
recognize_text
,
images
=
[
'tests/test.jpg'
]
)
def
test_recognize_text6
(
self
):
def
test_recognize_text6
(
self
):
self
.
assertRaises
(
self
.
assertRaises
(
AssertionError
,
self
.
module
.
recognize_text
,
paths
=
[
'no.jpg'
])
AssertionError
,
self
.
module
.
recognize_text
,
paths
=
[
'no.jpg'
]
)
def
test_save_inference_model
(
self
):
def
test_save_inference_model
(
self
):
self
.
module
.
save_inference_model
(
'./inference/model'
)
self
.
module
.
save_inference_model
(
'./inference/model'
)
...
...
modules/image/text_recognition/ch_pp-ocrv3/utils.py
浏览文件 @
283be69c
...
@@ -18,6 +18,7 @@ from __future__ import print_function
...
@@ -18,6 +18,7 @@ from __future__ import print_function
import
base64
import
base64
import
math
import
math
from
io
import
BytesIO
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
...
@@ -189,4 +190,17 @@ def base64_to_cv2(b64str):
...
@@ -189,4 +190,17 @@ def base64_to_cv2(b64str):
data
=
base64
.
b64decode
(
b64str
.
encode
(
'utf8'
))
data
=
base64
.
b64decode
(
b64str
.
encode
(
'utf8'
))
data
=
np
.
fromstring
(
data
,
np
.
uint8
)
data
=
np
.
fromstring
(
data
,
np
.
uint8
)
data
=
cv2
.
imdecode
(
data
,
cv2
.
IMREAD_COLOR
)
data
=
cv2
.
imdecode
(
data
,
cv2
.
IMREAD_COLOR
)
if
data
is
None
:
buf
=
BytesIO
()
image_decode
=
base64
.
b64decode
(
b64str
.
encode
(
'utf8'
))
image
=
BytesIO
(
image_decode
)
im
=
Image
.
open
(
image
)
rgb
=
im
.
convert
(
'RGB'
)
rgb
.
save
(
buf
,
'jpeg'
)
buf
.
seek
(
0
)
image_bytes
=
buf
.
read
()
data_base64
=
str
(
base64
.
b64encode
(
image_bytes
),
encoding
=
"utf-8"
)
image_decode
=
base64
.
b64decode
(
data_base64
)
img_array
=
np
.
frombuffer
(
image_decode
,
np
.
uint8
)
data
=
cv2
.
imdecode
(
img_array
,
cv2
.
IMREAD_COLOR
)
return
data
return
data
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录