Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
3ec57e8d
P
PaddleOCR
项目概览
weixin_41840029
/
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看板
未验证
提交
3ec57e8d
编写于
6月 01, 2021
作者:
D
Double_V
提交者:
GitHub
6月 01, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2919 from LDOUBLEV/benchmark_dyg
support img_directory predict
上级
b38f3534
a85941ff
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
23 deletion
+72
-23
deploy/cpp_infer/include/utility.h
deploy/cpp_infer/include/utility.h
+3
-0
deploy/cpp_infer/src/main.cpp
deploy/cpp_infer/src/main.cpp
+29
-19
deploy/cpp_infer/src/utility.cpp
deploy/cpp_infer/src/utility.cpp
+37
-2
deploy/cpp_infer/tools/build.sh
deploy/cpp_infer/tools/build.sh
+1
-0
deploy/cpp_infer/tools/config.txt
deploy/cpp_infer/tools/config.txt
+2
-2
未找到文件。
deploy/cpp_infer/include/utility.h
浏览文件 @
3ec57e8d
...
...
@@ -44,6 +44,9 @@ public:
inline
static
size_t
argmax
(
ForwardIterator
first
,
ForwardIterator
last
)
{
return
std
::
distance
(
first
,
std
::
max_element
(
first
,
last
));
}
static
void
GetAllFiles
(
const
char
*
dir_name
,
std
::
vector
<
std
::
string
>
&
all_inputs
);
};
}
// namespace PaddleOCR
\ No newline at end of file
deploy/cpp_infer/src/main.cpp
浏览文件 @
3ec57e8d
...
...
@@ -27,9 +27,12 @@
#include <fstream>
#include <numeric>
#include <glog/logging.h>
#include <include/config.h>
#include <include/ocr_det.h>
#include <include/ocr_rec.h>
#include <include/utility.h>
#include <sys/stat.h>
using
namespace
std
;
using
namespace
cv
;
...
...
@@ -47,13 +50,8 @@ int main(int argc, char **argv) {
config
.
PrintConfigInfo
();
std
::
string
img_path
(
argv
[
2
]);
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
if
(
!
srcimg
.
data
)
{
std
::
cerr
<<
"[ERROR] image read failed! image path: "
<<
img_path
<<
"
\n
"
;
exit
(
1
);
}
std
::
vector
<
std
::
string
>
all_img_names
;
Utility
::
GetAllFiles
((
char
*
)
img_path
.
c_str
(),
all_img_names
);
DBDetector
det
(
config
.
det_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
...
...
@@ -76,18 +74,30 @@ int main(int argc, char **argv) {
config
.
use_tensorrt
,
config
.
use_fp16
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
;
det
.
Run
(
srcimg
,
boxes
);
rec
.
Run
(
boxes
,
srcimg
,
cls
);
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
);
std
::
cout
<<
"Cost "
<<
double
(
duration
.
count
())
*
std
::
chrono
::
microseconds
::
period
::
num
/
std
::
chrono
::
microseconds
::
period
::
den
<<
"s"
<<
std
::
endl
;
for
(
auto
img_dir
:
all_img_names
)
{
LOG
(
INFO
)
<<
"The predict img: "
<<
img_dir
;
cv
::
Mat
srcimg
=
cv
::
imread
(
img_dir
,
cv
::
IMREAD_COLOR
);
if
(
!
srcimg
.
data
)
{
std
::
cerr
<<
"[ERROR] image read failed! image path: "
<<
img_path
<<
"
\n
"
;
exit
(
1
);
}
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
;
det
.
Run
(
srcimg
,
boxes
);
rec
.
Run
(
boxes
,
srcimg
,
cls
);
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
);
std
::
cout
<<
"Cost "
<<
double
(
duration
.
count
())
*
std
::
chrono
::
microseconds
::
period
::
num
/
std
::
chrono
::
microseconds
::
period
::
den
<<
"s"
<<
std
::
endl
;
}
return
0
;
}
deploy/cpp_infer/src/utility.cpp
浏览文件 @
3ec57e8d
...
...
@@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <dirent.h>
#include <include/utility.h>
#include <iostream>
#include <ostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#include <include/utility.h>
namespace
PaddleOCR
{
std
::
vector
<
std
::
string
>
Utility
::
ReadDict
(
const
std
::
string
&
path
)
{
...
...
@@ -57,4 +59,37 @@ void Utility::VisualizeBboxes(
<<
std
::
endl
;
}
// list all files under a directory
void
Utility
::
GetAllFiles
(
const
char
*
dir_name
,
std
::
vector
<
std
::
string
>
&
all_inputs
)
{
if
(
NULL
==
dir_name
)
{
std
::
cout
<<
" dir_name is null ! "
<<
std
::
endl
;
return
;
}
struct
stat
s
;
lstat
(
dir_name
,
&
s
);
if
(
!
S_ISDIR
(
s
.
st_mode
))
{
std
::
cout
<<
"dir_name is not a valid directory !"
<<
std
::
endl
;
all_inputs
.
push_back
(
dir_name
);
return
;
}
else
{
struct
dirent
*
filename
;
// return value for readdir()
DIR
*
dir
;
// return value for opendir()
dir
=
opendir
(
dir_name
);
if
(
NULL
==
dir
)
{
std
::
cout
<<
"Can not open dir "
<<
dir_name
<<
std
::
endl
;
return
;
}
std
::
cout
<<
"Successfully opened the dir !"
<<
std
::
endl
;
while
((
filename
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
filename
->
d_name
,
"."
)
==
0
||
strcmp
(
filename
->
d_name
,
".."
)
==
0
)
continue
;
// img_dir + std::string("/") + all_inputs[0];
all_inputs
.
push_back
(
dir_name
+
std
::
string
(
"/"
)
+
std
::
string
(
filename
->
d_name
));
}
}
}
}
// namespace PaddleOCR
\ No newline at end of file
deploy/cpp_infer/tools/build.sh
浏览文件 @
3ec57e8d
...
...
@@ -16,5 +16,6 @@ cmake .. \
-DOPENCV_DIR
=
${
OPENCV_DIR
}
\
-DCUDNN_LIB
=
${
CUDNN_LIB_DIR
}
\
-DCUDA_LIB
=
${
CUDA_LIB_DIR
}
\
-DTENSORRT_DIR
=
${
TENSORRT_DIR
}
\
make
-j
deploy/cpp_infer/tools/config.txt
浏览文件 @
3ec57e8d
...
...
@@ -20,10 +20,10 @@ cls_thresh 0.9
# rec config
rec_model_dir ./inference/ch_ppocr_mobile_v2.0_rec_infer/
char_list_file ../../ppocr/utils/ppocr_keys_v1.txt
char_list_file
../../ppocr/utils/ppocr_keys_v1.txt
# show the detection results
visualize
1
visualize
0
# use_tensorrt
use_tensorrt 0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录