Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
54cf0068
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看板
提交
54cf0068
编写于
7月 10, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
ff446b76
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
43 addition
and
69 deletion
+43
-69
deploy/lite/crnn_process.cc
deploy/lite/crnn_process.cc
+25
-50
deploy/lite/crnn_process.h
deploy/lite/crnn_process.h
+2
-4
deploy/lite/db_post_process.cc
deploy/lite/db_post_process.cc
+1
-1
deploy/lite/ocr_db_crnn.cc
deploy/lite/ocr_db_crnn.cc
+12
-12
deploy/lite/readme.md
deploy/lite/readme.md
+3
-2
未找到文件。
deploy/lite/crnn_process.cc
浏览文件 @
54cf0068
...
@@ -12,14 +12,14 @@
...
@@ -12,14 +12,14 @@
// 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 "crnn_process.h"
//NOLINT
#include "crnn_process.h" //NOLINT
#include <algorithm>
#include <algorithm>
#include <memory>
#include <memory>
#include <string>
#include <string>
const
std
::
vector
<
int
>
rec_image_shape
{
3
,
32
,
320
};
const
std
::
vector
<
int
>
rec_image_shape
{
3
,
32
,
320
};
cv
::
Mat
CrnnResizeNormImg
(
cv
::
Mat
img
,
float
wh_ratio
)
{
cv
::
Mat
CrnnResizeNormImg
(
cv
::
Mat
img
,
float
wh_ratio
,
bool
is_norm
)
{
int
imgC
,
imgH
,
imgW
;
int
imgC
,
imgH
,
imgW
;
imgC
=
rec_image_shape
[
0
];
imgC
=
rec_image_shape
[
0
];
imgW
=
rec_image_shape
[
2
];
imgW
=
rec_image_shape
[
2
];
...
@@ -34,54 +34,31 @@ cv::Mat CrnnResizeNormImg(cv::Mat img, float wh_ratio) {
...
@@ -34,54 +34,31 @@ cv::Mat CrnnResizeNormImg(cv::Mat img, float wh_ratio) {
else
else
resize_w
=
int
(
ceilf
(
imgH
*
ratio
));
resize_w
=
int
(
ceilf
(
imgH
*
ratio
));
cv
::
Mat
resize_img
;
cv
::
Mat
resize_img
;
cv
::
resize
(
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
resize_w
,
imgH
),
0.
f
,
0.
f
,
img
,
resize_img
,
cv
::
Size
(
resize_w
,
imgH
),
0.
f
,
0.
f
,
cv
::
INTER_CUBIC
);
cv
::
INTER_LINEAR
);
resize_img
.
convertTo
(
resize_img
,
CV_32FC3
,
1
/
255.
f
);
for
(
int
h
=
0
;
h
<
resize_img
.
rows
;
h
++
)
{
for
(
int
w
=
0
;
w
<
resize_img
.
cols
;
w
++
)
{
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
0
]
=
(
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
0
]
-
0.5
)
*
2
;
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
1
]
=
(
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
1
]
-
0.5
)
*
2
;
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
2
]
=
(
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
2
]
-
0.5
)
*
2
;
}
}
cv
::
Mat
dist
;
cv
::
copyMakeBorder
(
resize_img
,
dist
,
0
,
0
,
0
,
int
(
imgW
-
resize_w
),
cv
::
BORDER_CONSTANT
,
{
0
,
0
,
0
});
return
dist
;
}
cv
::
Mat
CrnnResizeImg
(
cv
::
Mat
img
,
float
wh_ratio
)
{
int
imgC
,
imgH
,
imgW
;
imgC
=
rec_image_shape
[
0
];
imgW
=
rec_image_shape
[
2
];
imgH
=
rec_image_shape
[
1
];
imgW
=
int
(
32
*
wh_ratio
);
if
(
!
is_norm
)
{
return
resize_img
;
}
else
{
resize_img
.
convertTo
(
resize_img
,
CV_32FC3
,
1
/
255.
f
);
for
(
int
h
=
0
;
h
<
resize_img
.
rows
;
h
++
)
{
for
(
int
w
=
0
;
w
<
resize_img
.
cols
;
w
++
)
{
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
0
]
=
(
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
0
]
-
0.5
)
*
2
;
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
1
]
=
(
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
1
]
-
0.5
)
*
2
;
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
2
]
=
(
resize_img
.
at
<
cv
::
Vec3f
>
(
h
,
w
)[
2
]
-
0.5
)
*
2
;
}
}
float
ratio
=
float
(
img
.
cols
)
/
float
(
img
.
rows
);
cv
::
Mat
dist
;
int
resize_w
,
resize_h
;
cv
::
copyMakeBorder
(
resize_img
,
dist
,
0
,
0
,
0
,
int
(
imgW
-
resize_w
),
if
(
ceilf
(
imgH
*
ratio
)
>
imgW
)
cv
::
BORDER_CONSTANT
,
{
0
,
0
,
0
});
resize_w
=
imgW
;
else
resize_w
=
int
(
ceilf
(
imgH
*
ratio
));
cv
::
Mat
resize_img
;
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
resize_w
,
imgH
),
0.
f
,
0.
f
,
cv
::
INTER_LINEAR
);
return
resize_img
;
return
dist
;
}
}
}
std
::
vector
<
std
::
string
>
ReadDict
(
std
::
string
path
)
{
std
::
vector
<
std
::
string
>
ReadDict
(
std
::
string
path
)
{
...
@@ -140,9 +117,7 @@ cv::Mat GetRotateCropImage(cv::Mat srcimage,
...
@@ -140,9 +117,7 @@ cv::Mat GetRotateCropImage(cv::Mat srcimage,
cv
::
Mat
M
=
cv
::
getPerspectiveTransform
(
pointsf
,
pts_std
);
cv
::
Mat
M
=
cv
::
getPerspectiveTransform
(
pointsf
,
pts_std
);
cv
::
Mat
dst_img
;
cv
::
Mat
dst_img
;
cv
::
warpPerspective
(
img_crop
,
cv
::
warpPerspective
(
img_crop
,
dst_img
,
M
,
dst_img
,
M
,
cv
::
Size
(
img_crop_width
,
img_crop_height
),
cv
::
Size
(
img_crop_width
,
img_crop_height
),
cv
::
BORDER_REPLICATE
);
cv
::
BORDER_REPLICATE
);
...
...
deploy/lite/crnn_process.h
浏览文件 @
54cf0068
...
@@ -21,14 +21,12 @@
...
@@ -21,14 +21,12 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include "math.h"
//NOLINT
#include "math.h" //NOLINT
#include "opencv2/core.hpp"
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc.hpp"
cv
::
Mat
CrnnResizeNormImg
(
cv
::
Mat
img
,
float
wh_ratio
);
cv
::
Mat
CrnnResizeNormImg
(
cv
::
Mat
img
,
float
wh_ratio
,
bool
is_norm
);
cv
::
Mat
CrnnResizeImg
(
cv
::
Mat
img
,
float
wh_ratio
);
std
::
vector
<
std
::
string
>
ReadDict
(
std
::
string
path
);
std
::
vector
<
std
::
string
>
ReadDict
(
std
::
string
path
);
...
...
deploy/lite/db_post_process.cc
浏览文件 @
54cf0068
...
@@ -276,4 +276,4 @@ FilterTagDetRes(std::vector<std::vector<std::vector<int>>> boxes, float ratio_h,
...
@@ -276,4 +276,4 @@ FilterTagDetRes(std::vector<std::vector<std::vector<int>>> boxes, float ratio_h,
root_points
.
push_back
(
boxes
[
n
]);
root_points
.
push_back
(
boxes
[
n
]);
}
}
return
root_points
;
return
root_points
;
}
}
\ No newline at end of file
deploy/lite/ocr_db_crnn.cc
浏览文件 @
54cf0068
...
@@ -107,8 +107,9 @@ cv::Mat DetResizeImg(const cv::Mat img, int max_size_len,
...
@@ -107,8 +107,9 @@ cv::Mat DetResizeImg(const cv::Mat img, int max_size_len,
void
RunRecModel
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
,
cv
::
Mat
img
,
void
RunRecModel
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
,
cv
::
Mat
img
,
std
::
shared_ptr
<
PaddlePredictor
>
predictor_crnn
,
std
::
shared_ptr
<
PaddlePredictor
>
predictor_crnn
,
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
<
std
::
string
>
charactor_dict
)
{
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
};
...
@@ -117,14 +118,12 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes, cv::Mat img,
...
@@ -117,14 +118,12 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes, cv::Mat img,
cv
::
Mat
crop_img
;
cv
::
Mat
crop_img
;
cv
::
Mat
resize_img
;
cv
::
Mat
resize_img
;
auto
charactor_dict
=
ReadDict
(
dict_path
);
int
index
=
0
;
int
index
=
0
;
for
(
int
i
=
boxes
.
size
()
-
1
;
i
>=
0
;
i
--
)
{
for
(
int
i
=
boxes
.
size
()
-
1
;
i
>=
0
;
i
--
)
{
crop_img
=
GetRotateCropImage
(
srcimg
,
boxes
[
i
]);
crop_img
=
GetRotateCropImage
(
srcimg
,
boxes
[
i
]);
float
wh_ratio
=
float
(
crop_img
.
cols
)
/
float
(
crop_img
.
rows
);
float
wh_ratio
=
float
(
crop_img
.
cols
)
/
float
(
crop_img
.
rows
);
resize_img
=
CrnnResize
Img
(
crop_img
,
wh_ratio
);
resize_img
=
CrnnResize
NormImg
(
crop_img
,
wh_ratio
,
false
);
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
);
...
@@ -227,13 +226,12 @@ RunDetModel(std::shared_ptr<PaddlePredictor> predictor, cv::Mat img,
...
@@ -227,13 +226,12 @@ RunDetModel(std::shared_ptr<PaddlePredictor> predictor, cv::Mat img,
auto
shape_out
=
output_tensor
->
shape
();
auto
shape_out
=
output_tensor
->
shape
();
// 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
]];
for
(
int
i
=
0
;
i
<
int
(
shape_out
[
2
]
*
shape_out
[
3
]);
i
++
)
{
for
(
int
i
=
0
;
i
<
int
(
shape_out
[
2
]
*
shape_out
[
3
]);
i
++
)
{
pred
[
int
(
i
/
int
(
shape_out
[
3
]))][
int
(
i
%
shape_out
[
3
])]
=
float
(
outptr
[
i
]);
pred
[
i
]
=
float
(
outptr
[
i
]);
cbuf
[
int
(
i
/
int
(
shape_out
[
3
]))][
int
(
i
%
shape_out
[
3
])]
=
cbuf
[
i
]
=
(
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
);
...
@@ -333,13 +331,15 @@ int main(int argc, char **argv) {
...
@@ -333,13 +331,15 @@ int main(int argc, char **argv) {
auto
det_predictor
=
loadModel
(
det_model_file
);
auto
det_predictor
=
loadModel
(
det_model_file
);
auto
rec_predictor
=
loadModel
(
rec_model_file
);
auto
rec_predictor
=
loadModel
(
rec_model_file
);
auto
charactor_dict
=
ReadDict
(
dict_path
);
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
auto
boxes
=
RunDetModel
(
det_predictor
,
srcimg
,
Config
);
auto
boxes
=
RunDetModel
(
det_predictor
,
srcimg
,
Config
);
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
(
boxes
,
srcimg
,
rec_predictor
,
dict_path
,
rec_text
,
RunRecModel
(
boxes
,
srcimg
,
rec_predictor
,
rec_text
,
rec_text_score
,
rec_text_score
);
charactor_dict
);
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
auto
duration
=
...
...
deploy/lite/readme.md
浏览文件 @
54cf0068
# PaddleOCR 模型部署
# PaddleOCR
端侧
模型部署
PaddleOCR是集训练、预测、端侧部署于一体的实用OCR工具库。本教程将介绍在安卓移动端部署PaddleOCR超轻量中文检测、识别模型的主要流程
。
本教程将介绍在移动端部署PaddleOCR超轻量中文检测、识别模型的详细步骤
。
## 1. 准备环境
## 1. 准备环境
...
@@ -159,6 +159,7 @@ demo/cxx/ocr/
...
@@ -159,6 +159,7 @@ demo/cxx/ocr/
| |--11.jpg 待测试图像
| |--11.jpg 待测试图像
| |--ppocr_keys_v1.txt 字典文件
| |--ppocr_keys_v1.txt 字典文件
| |--libpaddle_light_api_shared.so C++预测库文件
| |--libpaddle_light_api_shared.so C++预测库文件
| |--config.txt DB-CRNN超参数配置
|-- config.txt DB-CRNN超参数配置
|-- config.txt DB-CRNN超参数配置
|-- crnn_process.cc 识别模型CRNN的预处理和后处理文件
|-- crnn_process.cc 识别模型CRNN的预处理和后处理文件
|-- crnn_process.h
|-- crnn_process.h
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录