Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
69a7a140
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
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看板
提交
69a7a140
编写于
7月 13, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix visualization
上级
483486af
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
48 addition
and
20 deletion
+48
-20
deploy/cpp_infer/include/config.h
deploy/cpp_infer/include/config.h
+4
-0
deploy/cpp_infer/include/ocr_det.h
deploy/cpp_infer/include/ocr_det.h
+6
-1
deploy/cpp_infer/include/utility.h
deploy/cpp_infer/include/utility.h
+8
-0
deploy/cpp_infer/src/main.cpp
deploy/cpp_infer/src/main.cpp
+2
-1
deploy/cpp_infer/src/ocr_det.cpp
deploy/cpp_infer/src/ocr_det.cpp
+2
-18
deploy/cpp_infer/src/utility.cpp
deploy/cpp_infer/src/utility.cpp
+22
-0
deploy/cpp_infer/tools/config.txt
deploy/cpp_infer/tools/config.txt
+4
-0
未找到文件。
deploy/cpp_infer/include/config.h
浏览文件 @
69a7a140
...
...
@@ -52,6 +52,8 @@ public:
this
->
rec_model_dir
.
assign
(
config_map_
[
"rec_model_dir"
]);
this
->
char_list_file
.
assign
(
config_map_
[
"char_list_file"
]);
this
->
visualize
=
bool
(
stoi
(
config_map_
[
"visualize"
]));
}
bool
use_gpu
=
false
;
...
...
@@ -76,6 +78,8 @@ public:
std
::
string
char_list_file
;
bool
visualize
=
true
;
void
PrintConfigInfo
();
private:
...
...
deploy/cpp_infer/include/ocr_det.h
浏览文件 @
69a7a140
...
...
@@ -42,7 +42,8 @@ public:
const
int
&
max_side_len
=
960
,
const
double
&
det_db_thresh
=
0.3
,
const
double
&
det_db_box_thresh
=
0.5
,
const
double
&
det_db_unclip_ratio
=
2.0
)
{
const
double
&
det_db_unclip_ratio
=
2.0
,
const
bool
&
visualize
=
true
)
{
LoadModel
(
model_dir
);
this
->
use_gpu_
=
use_gpu
;
...
...
@@ -55,6 +56,8 @@ public:
this
->
det_db_thresh_
=
det_db_thresh
;
this
->
det_db_box_thresh_
=
det_db_box_thresh
;
this
->
det_db_unclip_ratio_
=
det_db_unclip_ratio
;
this
->
visualize_
=
visualize
;
}
// Load Paddle inference model
...
...
@@ -77,6 +80,8 @@ private:
double
det_db_box_thresh_
=
0.5
;
double
det_db_unclip_ratio_
=
2.0
;
bool
visualize_
=
true
;
std
::
vector
<
float
>
mean_
=
{
0.485
f
,
0.456
f
,
0.406
f
};
std
::
vector
<
float
>
scale_
=
{
1
/
0.229
f
,
1
/
0.224
f
,
1
/
0.225
f
};
bool
is_scale_
=
true
;
...
...
deploy/cpp_infer/include/utility.h
浏览文件 @
69a7a140
...
...
@@ -26,12 +26,20 @@
#include <fstream>
#include <numeric>
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
namespace
PaddleOCR
{
class
Utility
{
public:
static
std
::
vector
<
std
::
string
>
ReadDict
(
const
std
::
string
&
path
);
static
void
VisualizeBboxes
(
const
cv
::
Mat
&
srcimg
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
);
template
<
class
ForwardIterator
>
inline
static
size_t
argmax
(
ForwardIterator
first
,
ForwardIterator
last
)
{
return
std
::
distance
(
first
,
std
::
max_element
(
first
,
last
));
...
...
deploy/cpp_infer/src/main.cpp
浏览文件 @
69a7a140
...
...
@@ -53,7 +53,8 @@ int main(int argc, char **argv) {
DBDetector
det
(
config
.
det_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
max_side_len
,
config
.
det_db_thresh
,
config
.
det_db_box_thresh
,
config
.
det_db_unclip_ratio
);
config
.
det_db_box_thresh
,
config
.
det_db_unclip_ratio
,
config
.
visualize
);
CRNNRecognizer
rec
(
config
.
rec_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
char_list_file
);
...
...
deploy/cpp_infer/src/ocr_det.cpp
浏览文件 @
69a7a140
...
...
@@ -114,25 +114,9 @@ void DBDetector::Run(cv::Mat &img,
boxes
=
post_processor_
.
FilterTagDetRes
(
boxes
,
ratio_h
,
ratio_w
,
srcimg
);
//// visualization
cv
::
Point
rook_points
[
boxes
.
size
()][
4
];
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
for
(
int
m
=
0
;
m
<
boxes
[
0
].
size
();
m
++
)
{
rook_points
[
n
][
m
]
=
cv
::
Point
(
int
(
boxes
[
n
][
m
][
0
]),
int
(
boxes
[
n
][
m
][
1
]));
if
(
this
->
visualize_
)
{
Utility
::
VisualizeBboxes
(
srcimg
,
boxes
);
}
}
cv
::
Mat
img_vis
;
srcimg
.
copyTo
(
img_vis
);
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_points
[
n
]};
int
npt
[]
=
{
4
};
cv
::
polylines
(
img_vis
,
ppt
,
npt
,
1
,
1
,
CV_RGB
(
0
,
255
,
0
),
2
,
8
,
0
);
}
imwrite
(
"./det_res.png"
,
img_vis
);
std
::
cout
<<
"The detection visualized image saved in ./det_res.png"
<<
std
::
endl
;
}
}
// namespace PaddleOCR
\ No newline at end of file
deploy/cpp_infer/src/utility.cpp
浏览文件 @
69a7a140
...
...
@@ -36,4 +36,26 @@ std::vector<std::string> Utility::ReadDict(const std::string &path) {
return
m_vec
;
}
void
Utility
::
VisualizeBboxes
(
const
cv
::
Mat
&
srcimg
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
)
{
cv
::
Point
rook_points
[
boxes
.
size
()][
4
];
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
for
(
int
m
=
0
;
m
<
boxes
[
0
].
size
();
m
++
)
{
rook_points
[
n
][
m
]
=
cv
::
Point
(
int
(
boxes
[
n
][
m
][
0
]),
int
(
boxes
[
n
][
m
][
1
]));
}
}
cv
::
Mat
img_vis
;
srcimg
.
copyTo
(
img_vis
);
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_points
[
n
]};
int
npt
[]
=
{
4
};
cv
::
polylines
(
img_vis
,
ppt
,
npt
,
1
,
1
,
CV_RGB
(
0
,
255
,
0
),
2
,
8
,
0
);
}
cv
::
imwrite
(
"./ocr_vis.png"
,
img_vis
);
std
::
cout
<<
"The detection visualized image saved in ./ocr_vis.png.pn"
<<
std
::
endl
;
}
}
// namespace PaddleOCR
\ No newline at end of file
deploy/cpp_infer/tools/config.txt
浏览文件 @
69a7a140
...
...
@@ -15,3 +15,7 @@ det_model_dir ./inference/det_db
rec_model_dir ./inference/rec_crnn
char_list_file ./tools/ppocr_keys_v1.txt
img_path ../../doc/imgs/11.jpg
# show the detection results
visualize 1
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录