Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
2ab0ba91
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看板
提交
2ab0ba91
编写于
5月 26, 2021
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete debug code
上级
4ae833c5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
84 addition
and
89 deletion
+84
-89
deploy/cpp_infer/src/ocr_rec.cpp
deploy/cpp_infer/src/ocr_rec.cpp
+84
-89
未找到文件。
deploy/cpp_infer/src/ocr_rec.cpp
浏览文件 @
2ab0ba91
...
@@ -88,103 +88,98 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -88,103 +88,98 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
std
::
cout
<<
str_res
[
i
];
std
::
cout
<<
str_res
[
i
];
}
}
std
::
cout
<<
"
\t
score: "
<<
score
<<
std
::
endl
;
std
::
cout
<<
"
\t
score: "
<<
score
<<
std
::
endl
;
auto
box
=
boxes
[
i
];
std
::
cout
<<
"box: "
<<
box
[
0
][
0
]
<<
" "
<<
box
[
0
][
1
]
<<
" "
<<
box
[
1
][
0
]
<<
" "
<<
box
[
1
][
1
]
<<
" "
<<
box
[
2
][
0
]
<<
" "
<<
box
[
2
][
1
]
<<
" "
<<
box
[
3
][
0
]
<<
" "
<<
box
[
3
][
1
]
<<
" "
<<
std
::
endl
;
}
}
}
void
CRNNRecognizer
::
LoadModel
(
const
std
::
string
&
model_dir
)
{
// AnalysisConfig config;
paddle_infer
::
Config
config
;
config
.
SetModel
(
model_dir
+
"/inference.pdmodel"
,
model_dir
+
"/inference.pdiparams"
);
if
(
this
->
use_gpu_
)
{
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
if
(
this
->
use_tensorrt_
)
{
config
.
EnableTensorRtEngine
(
1
<<
20
,
10
,
3
,
this
->
use_fp16_
?
paddle_infer
::
Config
::
Precision
::
kHalf
:
paddle_infer
::
Config
::
Precision
::
kFloat32
,
false
,
false
);
}
}
else
{
config
.
DisableGpu
();
if
(
this
->
use_mkldnn_
)
{
config
.
EnableMKLDNN
();
// cache 10 different shapes for mkldnn to avoid memory leak
config
.
SetMkldnnCacheCapacity
(
10
);
}
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
);
}
config
.
SwitchUseFeedFetchOps
(
false
);
// true for multiple input
config
.
SwitchSpecifyInputNames
(
true
);
config
.
SwitchIrOptim
(
true
);
config
.
EnableMemoryOptim
();
config
.
DisableGlogInfo
();
this
->
predictor_
=
CreatePredictor
(
config
);
void
CRNNRecognizer
::
LoadModel
(
const
std
::
string
&
model_dir
)
{
}
// AnalysisConfig config;
paddle_infer
::
Config
config
;
config
.
SetModel
(
model_dir
+
"/inference.pdmodel"
,
model_dir
+
"/inference.pdiparams"
);
if
(
this
->
use_gpu_
)
{
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
if
(
this
->
use_tensorrt_
)
{
config
.
EnableTensorRtEngine
(
1
<<
20
,
10
,
3
,
this
->
use_fp16_
?
paddle_infer
::
Config
::
Precision
::
kHalf
:
paddle_infer
::
Config
::
Precision
::
kFloat32
,
false
,
false
);
}
}
else
{
config
.
DisableGpu
();
if
(
this
->
use_mkldnn_
)
{
config
.
EnableMKLDNN
();
// cache 10 different shapes for mkldnn to avoid memory leak
config
.
SetMkldnnCacheCapacity
(
10
);
}
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
);
}
cv
::
Mat
CRNNRecognizer
::
GetRotateCropImage
(
const
cv
::
Mat
&
srcimage
,
config
.
SwitchUseFeedFetchOps
(
false
);
std
::
vector
<
std
::
vector
<
int
>>
box
)
{
// true for multiple input
cv
::
Mat
image
;
config
.
SwitchSpecifyInputNames
(
true
);
srcimage
.
copyTo
(
image
);
std
::
vector
<
std
::
vector
<
int
>>
points
=
box
;
int
x_collect
[
4
]
=
{
box
[
0
][
0
],
box
[
1
][
0
],
box
[
2
][
0
],
box
[
3
][
0
]};
config
.
SwitchIrOptim
(
true
);
int
y_collect
[
4
]
=
{
box
[
0
][
1
],
box
[
1
][
1
],
box
[
2
][
1
],
box
[
3
][
1
]};
int
left
=
int
(
*
std
::
min_element
(
x_collect
,
x_collect
+
4
));
int
right
=
int
(
*
std
::
max_element
(
x_collect
,
x_collect
+
4
));
int
top
=
int
(
*
std
::
min_element
(
y_collect
,
y_collect
+
4
));
int
bottom
=
int
(
*
std
::
max_element
(
y_collect
,
y_collect
+
4
));
cv
::
Mat
img_crop
;
config
.
EnableMemoryOptim
()
;
image
(
cv
::
Rect
(
left
,
top
,
right
-
left
,
bottom
-
top
)).
copyTo
(
img_crop
);
config
.
DisableGlogInfo
(
);
for
(
int
i
=
0
;
i
<
points
.
size
();
i
++
)
{
this
->
predictor_
=
CreatePredictor
(
config
);
points
[
i
][
0
]
-=
left
;
points
[
i
][
1
]
-=
top
;
}
}
int
img_crop_width
=
int
(
sqrt
(
pow
(
points
[
0
][
0
]
-
points
[
1
][
0
],
2
)
+
cv
::
Mat
CRNNRecognizer
::
GetRotateCropImage
(
pow
(
points
[
0
][
1
]
-
points
[
1
][
1
],
2
)));
const
cv
::
Mat
&
srcimage
,
std
::
vector
<
std
::
vector
<
int
>>
box
)
{
int
img_crop_height
=
int
(
sqrt
(
pow
(
points
[
0
][
0
]
-
points
[
3
][
0
],
2
)
+
cv
::
Mat
image
;
pow
(
points
[
0
][
1
]
-
points
[
3
][
1
],
2
)));
srcimage
.
copyTo
(
image
);
std
::
vector
<
std
::
vector
<
int
>>
points
=
box
;
cv
::
Point2f
pts_std
[
4
];
pts_std
[
0
]
=
cv
::
Point2f
(
0.
,
0.
);
int
x_collect
[
4
]
=
{
box
[
0
][
0
],
box
[
1
][
0
],
box
[
2
][
0
],
box
[
3
][
0
]};
pts_std
[
1
]
=
cv
::
Point2f
(
img_crop_width
,
0.
);
int
y_collect
[
4
]
=
{
box
[
0
][
1
],
box
[
1
][
1
],
box
[
2
][
1
],
box
[
3
][
1
]};
pts_std
[
2
]
=
cv
::
Point2f
(
img_crop_width
,
img_crop_height
);
int
left
=
int
(
*
std
::
min_element
(
x_collect
,
x_collect
+
4
));
pts_std
[
3
]
=
cv
::
Point2f
(
0.
f
,
img_crop_height
);
int
right
=
int
(
*
std
::
max_element
(
x_collect
,
x_collect
+
4
));
int
top
=
int
(
*
std
::
min_element
(
y_collect
,
y_collect
+
4
));
cv
::
Point2f
pointsf
[
4
];
int
bottom
=
int
(
*
std
::
max_element
(
y_collect
,
y_collect
+
4
));
pointsf
[
0
]
=
cv
::
Point2f
(
points
[
0
][
0
],
points
[
0
][
1
]);
pointsf
[
1
]
=
cv
::
Point2f
(
points
[
1
][
0
],
points
[
1
][
1
]);
cv
::
Mat
img_crop
;
pointsf
[
2
]
=
cv
::
Point2f
(
points
[
2
][
0
],
points
[
2
][
1
]);
image
(
cv
::
Rect
(
left
,
top
,
right
-
left
,
bottom
-
top
)).
copyTo
(
img_crop
);
pointsf
[
3
]
=
cv
::
Point2f
(
points
[
3
][
0
],
points
[
3
][
1
]);
for
(
int
i
=
0
;
i
<
points
.
size
();
i
++
)
{
cv
::
Mat
M
=
cv
::
getPerspectiveTransform
(
pointsf
,
pts_std
);
points
[
i
][
0
]
-=
left
;
points
[
i
][
1
]
-=
top
;
cv
::
Mat
dst_img
;
}
cv
::
warpPerspective
(
img_crop
,
dst_img
,
M
,
cv
::
Size
(
img_crop_width
,
img_crop_height
),
int
img_crop_width
=
int
(
sqrt
(
pow
(
points
[
0
][
0
]
-
points
[
1
][
0
],
2
)
+
cv
::
BORDER_REPLICATE
);
pow
(
points
[
0
][
1
]
-
points
[
1
][
1
],
2
)));
int
img_crop_height
=
int
(
sqrt
(
pow
(
points
[
0
][
0
]
-
points
[
3
][
0
],
2
)
+
if
(
float
(
dst_img
.
rows
)
>=
float
(
dst_img
.
cols
)
*
1.5
)
{
pow
(
points
[
0
][
1
]
-
points
[
3
][
1
],
2
)));
cv
::
Mat
srcCopy
=
cv
::
Mat
(
dst_img
.
rows
,
dst_img
.
cols
,
dst_img
.
depth
());
cv
::
transpose
(
dst_img
,
srcCopy
);
cv
::
Point2f
pts_std
[
4
];
cv
::
flip
(
srcCopy
,
srcCopy
,
0
);
pts_std
[
0
]
=
cv
::
Point2f
(
0.
,
0.
);
return
srcCopy
;
pts_std
[
1
]
=
cv
::
Point2f
(
img_crop_width
,
0.
);
}
else
{
pts_std
[
2
]
=
cv
::
Point2f
(
img_crop_width
,
img_crop_height
);
return
dst_img
;
pts_std
[
3
]
=
cv
::
Point2f
(
0.
f
,
img_crop_height
);
cv
::
Point2f
pointsf
[
4
];
pointsf
[
0
]
=
cv
::
Point2f
(
points
[
0
][
0
],
points
[
0
][
1
]);
pointsf
[
1
]
=
cv
::
Point2f
(
points
[
1
][
0
],
points
[
1
][
1
]);
pointsf
[
2
]
=
cv
::
Point2f
(
points
[
2
][
0
],
points
[
2
][
1
]);
pointsf
[
3
]
=
cv
::
Point2f
(
points
[
3
][
0
],
points
[
3
][
1
]);
cv
::
Mat
M
=
cv
::
getPerspectiveTransform
(
pointsf
,
pts_std
);
cv
::
Mat
dst_img
;
cv
::
warpPerspective
(
img_crop
,
dst_img
,
M
,
cv
::
Size
(
img_crop_width
,
img_crop_height
),
cv
::
BORDER_REPLICATE
);
if
(
float
(
dst_img
.
rows
)
>=
float
(
dst_img
.
cols
)
*
1.5
)
{
cv
::
Mat
srcCopy
=
cv
::
Mat
(
dst_img
.
rows
,
dst_img
.
cols
,
dst_img
.
depth
());
cv
::
transpose
(
dst_img
,
srcCopy
);
cv
::
flip
(
srcCopy
,
srcCopy
,
0
);
return
srcCopy
;
}
else
{
return
dst_img
;
}
}
}
}
}
// namespace PaddleOCR
}
// namespace PaddleOCR
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录