Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Just_Paranoid
CnOCR
提交
13ed5e22
CnOCR
项目概览
Just_Paranoid
/
CnOCR
与 Fork 源项目一致
Fork自
Cloud IDE / CnOCR
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
CnOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
13ed5e22
编写于
5月 29, 2020
作者:
B
breezedeus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add `set_cand_alphabet`
上级
92d30bf2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
7 deletion
+31
-7
cnocr/cn_ocr.py
cnocr/cn_ocr.py
+14
-4
tests/test_cnocr.py
tests/test_cnocr.py
+17
-3
未找到文件。
cnocr/cn_ocr.py
浏览文件 @
13ed5e22
...
...
@@ -160,14 +160,12 @@ class CnOcr(object):
root
=
os
.
path
.
join
(
root
,
MODEL_VERSION
)
self
.
_model_dir
=
os
.
path
.
join
(
root
,
self
.
_model_name
)
self
.
_assert_and_prepare_model_files
()
self
.
_alphabet
,
inv_alph_dict
=
read_charset
(
self
.
_alphabet
,
self
.
_
inv_alph_dict
=
read_charset
(
os
.
path
.
join
(
self
.
_model_dir
,
'label_cn.txt'
)
)
self
.
_cand_alph_idx
=
None
if
cand_alphabet
is
not
None
:
self
.
_cand_alph_idx
=
[
0
]
+
[
inv_alph_dict
[
word
]
for
word
in
cand_alphabet
]
self
.
_cand_alph_idx
.
sort
()
self
.
set_cand_alphabet
(
cand_alphabet
)
self
.
_hp
=
Hyperparams
()
self
.
_hp
.
_loss_type
=
None
# infer mode
...
...
@@ -214,6 +212,18 @@ class CnOcr(object):
)
return
mod
def
set_cand_alphabet
(
self
,
cand_alphabet
):
"""
设置待识别字符的候选集合。
:param cand_alphabet: 待识别字符所在的候选集合。默认为 `None`,表示不限定识别字符范围
:return: None
"""
if
cand_alphabet
is
None
:
self
.
_cand_alph_idx
=
None
else
:
self
.
_cand_alph_idx
=
[
0
]
+
[
self
.
_inv_alph_dict
[
word
]
for
word
in
cand_alphabet
]
self
.
_cand_alph_idx
.
sort
()
def
ocr
(
self
,
img_fp
):
"""
:param img_fp: image file path; or color image mx.nd.NDArray or np.ndarray,
...
...
tests/test_cnocr.py
浏览文件 @
13ed5e22
...
...
@@ -177,9 +177,7 @@ def test_gray_aug(img_fp, expected):
print
(
res_img
.
shape
,
res_img
.
dtype
)
def
test_cand_alphabet
():
from
cnocr
import
NUMBERS
def
test_cand_alphabet1
():
img_fp
=
os
.
path
.
join
(
example_dir
,
'hybrid.png'
)
ocr
=
CnOcr
(
name
=
'instance1'
)
...
...
@@ -195,6 +193,22 @@ def test_cand_alphabet():
assert
len
(
pred
)
==
1
and
pred
[
0
]
==
'012345678'
def
test_cand_alphabet2
():
img_fp
=
os
.
path
.
join
(
example_dir
,
'hybrid.png'
)
ocr
=
CnOcr
(
name
=
'instance1'
)
pred
=
ocr
.
ocr
(
img_fp
)
pred
=
[
''
.
join
(
line_p
)
for
line_p
in
pred
]
print
(
"Predicted Chars:"
,
pred
)
assert
len
(
pred
)
==
1
and
pred
[
0
]
==
'o12345678'
ocr
.
set_cand_alphabet
(
NUMBERS
)
pred
=
ocr
.
ocr
(
img_fp
)
pred
=
[
''
.
join
(
line_p
)
for
line_p
in
pred
]
print
(
"Predicted Chars:"
,
pred
)
assert
len
(
pred
)
==
1
and
pred
[
0
]
==
'012345678'
INSTANCE_ID
=
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录