Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
d466d312
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看板
提交
d466d312
编写于
7月 07, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update .gitignore and delete unused code
上级
acae8ea8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
51 deletion
+41
-51
.gitignore
.gitignore
+1
-0
deploy/lite/ocr_db_crnn.cc
deploy/lite/ocr_db_crnn.cc
+40
-51
未找到文件。
.gitignore
浏览文件 @
d466d312
...
@@ -19,3 +19,4 @@ output/
...
@@ -19,3 +19,4 @@ output/
*.log
*.log
.clang-format
.clang-format
.clang_format.hook
deploy/lite/ocr_db_crnn.cc
浏览文件 @
d466d312
...
@@ -12,19 +12,17 @@
...
@@ -12,19 +12,17 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
#include "paddle_api.h" // NOLINT
#include <chrono>
#include <chrono>
#include "paddle_api.h" // NOLINT
#include "crnn_process.h"
#include "crnn_process.h"
#include "db_post_process.h"
#include "db_post_process.h"
using
namespace
paddle
::
lite_api
;
// NOLINT
using
namespace
paddle
::
lite_api
;
// NOLINT
using
namespace
std
;
using
namespace
std
;
// fill tensor with mean and scale and trans layout: nhwc -> nchw, neon speed up
// fill tensor with mean and scale and trans layout: nhwc -> nchw, neon speed up
void
neon_mean_scale
(
const
float
*
din
,
void
neon_mean_scale
(
const
float
*
din
,
float
*
dout
,
int
size
,
float
*
dout
,
int
size
,
const
std
::
vector
<
float
>
mean
,
const
std
::
vector
<
float
>
mean
,
const
std
::
vector
<
float
>
scale
)
{
const
std
::
vector
<
float
>
scale
)
{
if
(
mean
.
size
()
!=
3
||
scale
.
size
()
!=
3
)
{
if
(
mean
.
size
()
!=
3
||
scale
.
size
()
!=
3
)
{
...
@@ -38,9 +36,9 @@ void neon_mean_scale(const float* din,
...
@@ -38,9 +36,9 @@ void neon_mean_scale(const float* din,
float32x4_t
vscale1
=
vdupq_n_f32
(
scale
[
1
]);
float32x4_t
vscale1
=
vdupq_n_f32
(
scale
[
1
]);
float32x4_t
vscale2
=
vdupq_n_f32
(
scale
[
2
]);
float32x4_t
vscale2
=
vdupq_n_f32
(
scale
[
2
]);
float
*
dout_c0
=
dout
;
float
*
dout_c0
=
dout
;
float
*
dout_c1
=
dout
+
size
;
float
*
dout_c1
=
dout
+
size
;
float
*
dout_c2
=
dout
+
size
*
2
;
float
*
dout_c2
=
dout
+
size
*
2
;
int
i
=
0
;
int
i
=
0
;
for
(;
i
<
size
-
3
;
i
+=
4
)
{
for
(;
i
<
size
-
3
;
i
+=
4
)
{
...
@@ -68,9 +66,8 @@ void neon_mean_scale(const float* din,
...
@@ -68,9 +66,8 @@ void neon_mean_scale(const float* din,
}
}
// resize image to a size multiple of 32 which is required by the network
// resize image to a size multiple of 32 which is required by the network
cv
::
Mat
DetResizeImg
(
const
cv
::
Mat
img
,
cv
::
Mat
DetResizeImg
(
const
cv
::
Mat
img
,
int
max_size_len
,
int
max_size_len
,
std
::
vector
<
float
>
&
ratio_hw
)
{
std
::
vector
<
float
>&
ratio_hw
)
{
int
w
=
img
.
cols
;
int
w
=
img
.
cols
;
int
h
=
img
.
rows
;
int
h
=
img
.
rows
;
...
@@ -108,12 +105,10 @@ cv::Mat DetResizeImg(const cv::Mat img,
...
@@ -108,12 +105,10 @@ cv::Mat DetResizeImg(const cv::Mat img,
return
resize_img
;
return
resize_img
;
}
}
void
RunRecModel
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
,
void
RunRecModel
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
,
cv
::
Mat
img
,
cv
::
Mat
img
,
std
::
shared_ptr
<
PaddlePredictor
>
predictor_crnn
,
std
::
shared_ptr
<
PaddlePredictor
>
predictor_crnn
,
std
::
string
dict_path
,
std
::
string
dict_path
,
std
::
vector
<
std
::
string
>
&
rec_text
,
std
::
vector
<
std
::
string
>&
rec_text
,
std
::
vector
<
float
>
&
rec_text_score
)
{
std
::
vector
<
float
>&
rec_text_score
)
{
std
::
vector
<
float
>
mean
=
{
0.5
f
,
0.5
f
,
0.5
f
};
std
::
vector
<
float
>
mean
=
{
0.5
f
,
0.5
f
,
0.5
f
};
std
::
vector
<
float
>
scale
=
{
1
/
0.5
f
,
1
/
0.5
f
,
1
/
0.5
f
};
std
::
vector
<
float
>
scale
=
{
1
/
0.5
f
,
1
/
0.5
f
,
1
/
0.5
f
};
...
@@ -132,22 +127,22 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -132,22 +127,22 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
resize_img
=
CrnnResizeImg
(
crop_img
,
wh_ratio
);
resize_img
=
CrnnResizeImg
(
crop_img
,
wh_ratio
);
resize_img
.
convertTo
(
resize_img
,
CV_32FC3
,
1
/
255.
f
);
resize_img
.
convertTo
(
resize_img
,
CV_32FC3
,
1
/
255.
f
);
const
float
*
dimg
=
reinterpret_cast
<
const
float
*>
(
resize_img
.
data
);
const
float
*
dimg
=
reinterpret_cast
<
const
float
*>
(
resize_img
.
data
);
std
::
unique_ptr
<
Tensor
>
input_tensor0
(
std
::
unique_ptr
<
Tensor
>
input_tensor0
(
std
::
move
(
predictor_crnn
->
GetInput
(
0
)));
std
::
move
(
predictor_crnn
->
GetInput
(
0
)));
input_tensor0
->
Resize
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_tensor0
->
Resize
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
auto
*
data0
=
input_tensor0
->
mutable_data
<
float
>
();
auto
*
data0
=
input_tensor0
->
mutable_data
<
float
>
();
neon_mean_scale
(
neon_mean_scale
(
dimg
,
data0
,
resize_img
.
rows
*
resize_img
.
cols
,
mean
,
dimg
,
data0
,
resize_img
.
rows
*
resize_img
.
cols
,
mean
,
scale
);
scale
);
//// Run CRNN predictor
//// Run CRNN predictor
predictor_crnn
->
Run
();
predictor_crnn
->
Run
();
// Get output and run postprocess
// Get output and run postprocess
std
::
unique_ptr
<
const
Tensor
>
output_tensor0
(
std
::
unique_ptr
<
const
Tensor
>
output_tensor0
(
std
::
move
(
predictor_crnn
->
GetOutput
(
0
)));
std
::
move
(
predictor_crnn
->
GetOutput
(
0
)));
auto
*
rec_idx
=
output_tensor0
->
data
<
int
>
();
auto
*
rec_idx
=
output_tensor0
->
data
<
int
>
();
auto
rec_idx_lod
=
output_tensor0
->
lod
();
auto
rec_idx_lod
=
output_tensor0
->
lod
();
auto
shape_out
=
output_tensor0
->
shape
();
auto
shape_out
=
output_tensor0
->
shape
();
...
@@ -158,7 +153,8 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -158,7 +153,8 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
pred_idx
.
push_back
(
int
(
rec_idx
[
n
]));
pred_idx
.
push_back
(
int
(
rec_idx
[
n
]));
}
}
if
(
pred_idx
.
size
()
<
1e-3
)
continue
;
if
(
pred_idx
.
size
()
<
1e-3
)
continue
;
index
+=
1
;
index
+=
1
;
std
::
string
pred_txt
=
""
;
std
::
string
pred_txt
=
""
;
...
@@ -170,7 +166,7 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -170,7 +166,7 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
////get score
////get score
std
::
unique_ptr
<
const
Tensor
>
output_tensor1
(
std
::
unique_ptr
<
const
Tensor
>
output_tensor1
(
std
::
move
(
predictor_crnn
->
GetOutput
(
1
)));
std
::
move
(
predictor_crnn
->
GetOutput
(
1
)));
auto
*
predict_batch
=
output_tensor1
->
data
<
float
>
();
auto
*
predict_batch
=
output_tensor1
->
data
<
float
>
();
auto
predict_shape
=
output_tensor1
->
shape
();
auto
predict_shape
=
output_tensor1
->
shape
();
auto
predict_lod
=
output_tensor1
->
lod
();
auto
predict_lod
=
output_tensor1
->
lod
();
...
@@ -198,10 +194,9 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -198,10 +194,9 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
}
}
}
}
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
RunDetModel
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
std
::
shared_ptr
<
PaddlePredictor
>
predictor
,
RunDetModel
(
std
::
shared_ptr
<
PaddlePredictor
>
predictor
,
cv
::
Mat
img
,
cv
::
Mat
img
,
std
::
map
<
std
::
string
,
double
>
Config
)
{
std
::
map
<
std
::
string
,
double
>
Config
)
{
// Read img
// Read img
int
max_side_len
=
int
(
Config
[
"max_side_len"
]);
int
max_side_len
=
int
(
Config
[
"max_side_len"
]);
...
@@ -216,11 +211,11 @@ std::vector<std::vector<std::vector<int>>> RunDetModel(
...
@@ -216,11 +211,11 @@ std::vector<std::vector<std::vector<int>>> RunDetModel(
// Prepare input data from image
// Prepare input data from image
std
::
unique_ptr
<
Tensor
>
input_tensor0
(
std
::
move
(
predictor
->
GetInput
(
0
)));
std
::
unique_ptr
<
Tensor
>
input_tensor0
(
std
::
move
(
predictor
->
GetInput
(
0
)));
input_tensor0
->
Resize
({
1
,
3
,
img_fp
.
rows
,
img_fp
.
cols
});
input_tensor0
->
Resize
({
1
,
3
,
img_fp
.
rows
,
img_fp
.
cols
});
auto
*
data0
=
input_tensor0
->
mutable_data
<
float
>
();
auto
*
data0
=
input_tensor0
->
mutable_data
<
float
>
();
std
::
vector
<
float
>
mean
=
{
0.485
f
,
0.456
f
,
0.406
f
};
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
};
std
::
vector
<
float
>
scale
=
{
1
/
0.229
f
,
1
/
0.224
f
,
1
/
0.225
f
};
const
float
*
dimg
=
reinterpret_cast
<
const
float
*>
(
img_fp
.
data
);
const
float
*
dimg
=
reinterpret_cast
<
const
float
*>
(
img_fp
.
data
);
neon_mean_scale
(
dimg
,
data0
,
img_fp
.
rows
*
img_fp
.
cols
,
mean
,
scale
);
neon_mean_scale
(
dimg
,
data0
,
img_fp
.
rows
*
img_fp
.
cols
,
mean
,
scale
);
// Run predictor
// Run predictor
...
@@ -229,15 +224,9 @@ std::vector<std::vector<std::vector<int>>> RunDetModel(
...
@@ -229,15 +224,9 @@ std::vector<std::vector<std::vector<int>>> RunDetModel(
// Get output and post process
// Get output and post process
std
::
unique_ptr
<
const
Tensor
>
output_tensor
(
std
::
unique_ptr
<
const
Tensor
>
output_tensor
(
std
::
move
(
predictor
->
GetOutput
(
0
)));
std
::
move
(
predictor
->
GetOutput
(
0
)));
auto
*
outptr
=
output_tensor
->
data
<
float
>
();
auto
*
outptr
=
output_tensor
->
data
<
float
>
();
auto
shape_out
=
output_tensor
->
shape
();
auto
shape_out
=
output_tensor
->
shape
();
int64_t
out_numl
=
1
;
double
sum
=
0
;
for
(
auto
i
:
shape_out
)
{
out_numl
*=
i
;
}
// Save output
// Save output
float
pred
[
shape_out
[
2
]][
shape_out
[
3
]];
float
pred
[
shape_out
[
2
]][
shape_out
[
3
]];
unsigned
char
cbuf
[
shape_out
[
2
]][
shape_out
[
3
]];
unsigned
char
cbuf
[
shape_out
[
2
]][
shape_out
[
3
]];
...
@@ -248,8 +237,8 @@ std::vector<std::vector<std::vector<int>>> RunDetModel(
...
@@ -248,8 +237,8 @@ std::vector<std::vector<std::vector<int>>> RunDetModel(
(
unsigned
char
)((
outptr
[
i
])
*
255
);
(
unsigned
char
)((
outptr
[
i
])
*
255
);
}
}
cv
::
Mat
cbuf_map
(
shape_out
[
2
],
shape_out
[
3
],
CV_8UC1
,
(
unsigned
char
*
)
cbuf
);
cv
::
Mat
cbuf_map
(
shape_out
[
2
],
shape_out
[
3
],
CV_8UC1
,
(
unsigned
char
*
)
cbuf
);
cv
::
Mat
pred_map
(
shape_out
[
2
],
shape_out
[
3
],
CV_32F
,
(
float
*
)
pred
);
cv
::
Mat
pred_map
(
shape_out
[
2
],
shape_out
[
3
],
CV_32F
,
(
float
*
)
pred
);
const
double
threshold
=
double
(
Config
[
"det_db_thresh"
])
*
255
;
const
double
threshold
=
double
(
Config
[
"det_db_thresh"
])
*
255
;
const
double
maxvalue
=
255
;
const
double
maxvalue
=
255
;
...
@@ -284,28 +273,28 @@ cv::Mat Visualization(cv::Mat srcimg,
...
@@ -284,28 +273,28 @@ cv::Mat Visualization(cv::Mat srcimg,
cv
::
Mat
img_vis
;
cv
::
Mat
img_vis
;
srcimg
.
copyTo
(
img_vis
);
srcimg
.
copyTo
(
img_vis
);
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_points
[
n
]};
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_points
[
n
]};
int
npt
[]
=
{
4
};
int
npt
[]
=
{
4
};
cv
::
polylines
(
img_vis
,
ppt
,
npt
,
1
,
1
,
CV_RGB
(
0
,
255
,
0
),
2
,
8
,
0
);
cv
::
polylines
(
img_vis
,
ppt
,
npt
,
1
,
1
,
CV_RGB
(
0
,
255
,
0
),
2
,
8
,
0
);
}
}
cv
::
imwrite
(
"./imgs/vis.jpg"
,
img_vis
);
cv
::
imwrite
(
"./vis.jpg"
,
img_vis
);
std
::
cout
<<
"The detection visualized image saved in ./imgs/vis.jpg"
std
::
cout
<<
"The detection visualized image saved in ./vis.jpg"
<<
std
::
endl
;
<<
std
::
endl
;
return
img_vis
;
return
img_vis
;
}
}
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
str
,
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
str
,
const
std
::
string
&
delim
)
{
const
std
::
string
&
delim
)
{
std
::
vector
<
std
::
string
>
res
;
std
::
vector
<
std
::
string
>
res
;
if
(
""
==
str
)
return
res
;
if
(
""
==
str
)
char
*
strs
=
new
char
[
str
.
length
()
+
1
];
return
res
;
char
*
strs
=
new
char
[
str
.
length
()
+
1
];
std
::
strcpy
(
strs
,
str
.
c_str
());
std
::
strcpy
(
strs
,
str
.
c_str
());
char
*
d
=
new
char
[
delim
.
length
()
+
1
];
char
*
d
=
new
char
[
delim
.
length
()
+
1
];
std
::
strcpy
(
d
,
delim
.
c_str
());
std
::
strcpy
(
d
,
delim
.
c_str
());
char
*
p
=
std
::
strtok
(
strs
,
d
);
char
*
p
=
std
::
strtok
(
strs
,
d
);
while
(
p
)
{
while
(
p
)
{
string
s
=
p
;
string
s
=
p
;
res
.
push_back
(
s
);
res
.
push_back
(
s
);
...
@@ -326,7 +315,7 @@ std::map<std::string, double> LoadConfigTxt(std::string config_path) {
...
@@ -326,7 +315,7 @@ std::map<std::string, double> LoadConfigTxt(std::string config_path) {
return
dict
;
return
dict
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
5
)
{
if
(
argc
<
5
)
{
std
::
cerr
<<
"[ERROR] usage: "
<<
argv
[
0
]
std
::
cerr
<<
"[ERROR] usage: "
<<
argv
[
0
]
<<
" det_model_file rec_model_file image_path
\n
"
;
<<
" det_model_file rec_model_file image_path
\n
"
;
...
@@ -350,8 +339,8 @@ int main(int argc, char** argv) {
...
@@ -350,8 +339,8 @@ int main(int argc, char** argv) {
std
::
vector
<
std
::
string
>
rec_text
;
std
::
vector
<
std
::
string
>
rec_text
;
std
::
vector
<
float
>
rec_text_score
;
std
::
vector
<
float
>
rec_text_score
;
RunRecModel
(
RunRecModel
(
boxes
,
srcimg
,
rec_predictor
,
dict_path
,
rec_text
,
boxes
,
srcimg
,
rec_predictor
,
dict_path
,
rec_text
,
rec_text_score
);
rec_text_score
);
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
auto
duration
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录