Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
c9841fe2
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看板
未验证
提交
c9841fe2
编写于
4月 23, 2021
作者:
M
MissPenguin
提交者:
GitHub
4月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2606 from littletomatodonkey/dyg/add_db_post
add new db post score calculation method
上级
718b8ca4
eafb157a
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
72 addition
and
1 deletion
+72
-1
deploy/cpp_infer/include/postprocess_op.h
deploy/cpp_infer/include/postprocess_op.h
+1
-0
deploy/cpp_infer/src/postprocess_op.cpp
deploy/cpp_infer/src/postprocess_op.cpp
+35
-0
ppocr/postprocess/db_postprocess.py
ppocr/postprocess/db_postprocess.py
+34
-1
tools/infer/predict_det.py
tools/infer/predict_det.py
+1
-0
tools/infer/utility.py
tools/infer/utility.py
+1
-0
未找到文件。
deploy/cpp_infer/include/postprocess_op.h
浏览文件 @
c9841fe2
...
...
@@ -51,6 +51,7 @@ public:
float
&
ssid
);
float
BoxScoreFast
(
std
::
vector
<
std
::
vector
<
float
>>
box_array
,
cv
::
Mat
pred
);
float
PolygonScoreAcc
(
std
::
vector
<
cv
::
Point
>
contour
,
cv
::
Mat
pred
);
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
BoxesFromBitmap
(
const
cv
::
Mat
pred
,
const
cv
::
Mat
bitmap
,
...
...
deploy/cpp_infer/src/postprocess_op.cpp
浏览文件 @
c9841fe2
...
...
@@ -159,6 +159,39 @@ std::vector<std::vector<float>> PostProcessor::GetMiniBoxes(cv::RotatedRect box,
return
array
;
}
float
PostProcessor
::
PolygonScoreAcc
(
std
::
vector
<
cv
::
Point
>
contour
,
cv
::
Mat
pred
){
int
width
=
pred
.
cols
;
int
height
=
pred
.
rows
;
std
::
vector
<
float
>
box_x
;
std
::
vector
<
float
>
box_y
;
for
(
int
i
=
0
;
i
<
contour
.
size
();
++
i
){
box_x
.
push_back
(
contour
[
i
].
x
);
box_y
.
push_back
(
contour
[
i
].
y
);
}
int
xmin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_x
.
begin
(),
box_x
.
end
())))),
0
,
width
-
1
);
int
xmax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_x
.
begin
(),
box_x
.
end
())))),
0
,
width
-
1
);
int
ymin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_y
.
begin
(),
box_y
.
end
())))),
0
,
height
-
1
);
int
ymax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_y
.
begin
(),
box_y
.
end
())))),
0
,
height
-
1
);
cv
::
Mat
mask
;
mask
=
cv
::
Mat
::
zeros
(
ymax
-
ymin
+
1
,
xmax
-
xmin
+
1
,
CV_8UC1
);
cv
::
Point
rook_point
[
contour
.
size
()];
for
(
int
i
=
0
;
i
<
contour
.
size
();
++
i
){
rook_point
[
i
]
=
cv
::
Point
(
int
(
box_x
[
i
])
-
xmin
,
int
(
box_y
[
i
])
-
ymin
);
}
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_point
};
int
npt
[]
=
{
int
(
contour
.
size
())};
cv
::
fillPoly
(
mask
,
ppt
,
npt
,
1
,
cv
::
Scalar
(
1
));
cv
::
Mat
croppedImg
;
pred
(
cv
::
Rect
(
xmin
,
ymin
,
xmax
-
xmin
+
1
,
ymax
-
ymin
+
1
)).
copyTo
(
croppedImg
);
float
score
=
cv
::
mean
(
croppedImg
,
mask
)[
0
];
return
score
;
}
float
PostProcessor
::
BoxScoreFast
(
std
::
vector
<
std
::
vector
<
float
>>
box_array
,
cv
::
Mat
pred
)
{
auto
array
=
box_array
;
...
...
@@ -235,6 +268,8 @@ PostProcessor::BoxesFromBitmap(const cv::Mat pred, const cv::Mat bitmap,
float
score
;
score
=
BoxScoreFast
(
array
,
pred
);
/* compute using polygon*/
// score = PolygonScoreAcc(contours[_i], pred);
if
(
score
<
box_thresh
)
continue
;
...
...
ppocr/postprocess/db_postprocess.py
浏览文件 @
c9841fe2
...
...
@@ -34,12 +34,18 @@ class DBPostProcess(object):
max_candidates
=
1000
,
unclip_ratio
=
2.0
,
use_dilation
=
False
,
score_mode
=
"fast"
,
**
kwargs
):
self
.
thresh
=
thresh
self
.
box_thresh
=
box_thresh
self
.
max_candidates
=
max_candidates
self
.
unclip_ratio
=
unclip_ratio
self
.
min_size
=
3
self
.
score_mode
=
score_mode
assert
score_mode
in
[
"slow"
,
"fast"
],
"Score mode must be in [slow, fast] but got: {}"
.
format
(
score_mode
)
self
.
dilation_kernel
=
None
if
not
use_dilation
else
np
.
array
(
[[
1
,
1
],
[
1
,
1
]])
...
...
@@ -69,7 +75,10 @@ class DBPostProcess(object):
if
sside
<
self
.
min_size
:
continue
points
=
np
.
array
(
points
)
if
self
.
score_mode
==
"fast"
:
score
=
self
.
box_score_fast
(
pred
,
points
.
reshape
(
-
1
,
2
))
else
:
score
=
self
.
box_score_slow
(
pred
,
contour
)
if
self
.
box_thresh
>
score
:
continue
...
...
@@ -120,6 +129,9 @@ class DBPostProcess(object):
return
box
,
min
(
bounding_box
[
1
])
def
box_score_fast
(
self
,
bitmap
,
_box
):
'''
box_score_fast: use bbox mean score as the mean score
'''
h
,
w
=
bitmap
.
shape
[:
2
]
box
=
_box
.
copy
()
xmin
=
np
.
clip
(
np
.
floor
(
box
[:,
0
].
min
()).
astype
(
np
.
int
),
0
,
w
-
1
)
...
...
@@ -133,6 +145,27 @@ class DBPostProcess(object):
cv2
.
fillPoly
(
mask
,
box
.
reshape
(
1
,
-
1
,
2
).
astype
(
np
.
int32
),
1
)
return
cv2
.
mean
(
bitmap
[
ymin
:
ymax
+
1
,
xmin
:
xmax
+
1
],
mask
)[
0
]
def
box_score_slow
(
self
,
bitmap
,
contour
):
'''
box_score_slow: use polyon mean score as the mean score
'''
h
,
w
=
bitmap
.
shape
[:
2
]
contour
=
contour
.
copy
()
contour
=
np
.
reshape
(
contour
,
(
-
1
,
2
))
xmin
=
np
.
clip
(
np
.
min
(
contour
[:,
0
]),
0
,
w
-
1
)
xmax
=
np
.
clip
(
np
.
max
(
contour
[:,
0
]),
0
,
w
-
1
)
ymin
=
np
.
clip
(
np
.
min
(
contour
[:,
1
]),
0
,
h
-
1
)
ymax
=
np
.
clip
(
np
.
max
(
contour
[:,
1
]),
0
,
h
-
1
)
mask
=
np
.
zeros
((
ymax
-
ymin
+
1
,
xmax
-
xmin
+
1
),
dtype
=
np
.
uint8
)
contour
[:,
0
]
=
contour
[:,
0
]
-
xmin
contour
[:,
1
]
=
contour
[:,
1
]
-
ymin
cv2
.
fillPoly
(
mask
,
contour
.
reshape
(
1
,
-
1
,
2
).
astype
(
np
.
int32
),
1
)
return
cv2
.
mean
(
bitmap
[
ymin
:
ymax
+
1
,
xmin
:
xmax
+
1
],
mask
)[
0
]
def
__call__
(
self
,
outs_dict
,
shape_list
):
pred
=
outs_dict
[
'maps'
]
if
isinstance
(
pred
,
paddle
.
Tensor
):
...
...
tools/infer/predict_det.py
浏览文件 @
c9841fe2
...
...
@@ -62,6 +62,7 @@ class TextDetector(object):
postprocess_params
[
"max_candidates"
]
=
1000
postprocess_params
[
"unclip_ratio"
]
=
args
.
det_db_unclip_ratio
postprocess_params
[
"use_dilation"
]
=
args
.
use_dilation
postprocess_params
[
"score_mode"
]
=
args
.
det_db_score_mode
elif
self
.
det_algorithm
==
"EAST"
:
postprocess_params
[
'name'
]
=
'EASTPostProcess'
postprocess_params
[
"score_thresh"
]
=
args
.
det_east_score_thresh
...
...
tools/infer/utility.py
浏览文件 @
c9841fe2
...
...
@@ -48,6 +48,7 @@ def parse_args():
parser
.
add_argument
(
"--det_db_unclip_ratio"
,
type
=
float
,
default
=
1.6
)
parser
.
add_argument
(
"--max_batch_size"
,
type
=
int
,
default
=
10
)
parser
.
add_argument
(
"--use_dilation"
,
type
=
bool
,
default
=
False
)
parser
.
add_argument
(
"--det_db_score_mode"
,
type
=
str
,
default
=
"fast"
)
# EAST parmas
parser
.
add_argument
(
"--det_east_score_thresh"
,
type
=
float
,
default
=
0.8
)
parser
.
add_argument
(
"--det_east_cover_thresh"
,
type
=
float
,
default
=
0.1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录