Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
874a3262
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看板
提交
874a3262
编写于
8月 11, 2021
作者:
M
MissPenguin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge shared files
上级
39b7263e
变更
18
展开全部
显示空白变更内容
内联
并排
Showing
18 changed file
with
73 addition
and
10027 deletion
+73
-10027
deploy/cpp_infer/include/clipper.cpp
deploy/cpp_infer/include/clipper.cpp
+0
-0
deploy/cpp_infer/include/postprocess_op.cpp
deploy/cpp_infer/include/postprocess_op.cpp
+1
-0
deploy/cpp_infer/include/postprocess_op.h
deploy/cpp_infer/include/postprocess_op.h
+1
-0
deploy/cpp_infer/include/preprocess_op.cpp
deploy/cpp_infer/include/preprocess_op.cpp
+0
-0
deploy/cpp_infer/include/utility.h
deploy/cpp_infer/include/utility.h
+66
-4
deploy/cpp_infer/src_det/clipper.cpp
deploy/cpp_infer/src_det/clipper.cpp
+0
-4380
deploy/cpp_infer/src_det/ocr_det.cpp
deploy/cpp_infer/src_det/ocr_det.cpp
+2
-0
deploy/cpp_infer/src_det/postprocess_op.cpp
deploy/cpp_infer/src_det/postprocess_op.cpp
+0
-355
deploy/cpp_infer/src_det/utility.cpp
deploy/cpp_infer/src_det/utility.cpp
+0
-95
deploy/cpp_infer/src_rec/ocr_rec.cpp
deploy/cpp_infer/src_rec/ocr_rec.cpp
+1
-0
deploy/cpp_infer/src_rec/preprocess_op.cpp
deploy/cpp_infer/src_rec/preprocess_op.cpp
+0
-133
deploy/cpp_infer/src_rec/utility.cpp
deploy/cpp_infer/src_rec/utility.cpp
+0
-95
deploy/cpp_infer/src_system/clipper.cpp
deploy/cpp_infer/src_system/clipper.cpp
+0
-4380
deploy/cpp_infer/src_system/main.cpp
deploy/cpp_infer/src_system/main.cpp
+0
-2
deploy/cpp_infer/src_system/ocr_det.cpp
deploy/cpp_infer/src_system/ocr_det.cpp
+2
-0
deploy/cpp_infer/src_system/postprocess_op.cpp
deploy/cpp_infer/src_system/postprocess_op.cpp
+0
-355
deploy/cpp_infer/src_system/preprocess_op.cpp
deploy/cpp_infer/src_system/preprocess_op.cpp
+0
-133
deploy/cpp_infer/src_system/utility.cpp
deploy/cpp_infer/src_system/utility.cpp
+0
-95
未找到文件。
deploy/cpp_infer/
src_rec
/clipper.cpp
→
deploy/cpp_infer/
include
/clipper.cpp
浏览文件 @
874a3262
文件已移动
deploy/cpp_infer/
src_rec
/postprocess_op.cpp
→
deploy/cpp_infer/
include
/postprocess_op.cpp
浏览文件 @
874a3262
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#include <include/postprocess_op.h>
#include <include/clipper.cpp>
namespace
PaddleOCR
{
...
...
deploy/cpp_infer/include/postprocess_op.h
浏览文件 @
874a3262
...
...
@@ -30,6 +30,7 @@
#include "include/clipper.h"
#include "include/utility.h"
using
namespace
std
;
namespace
PaddleOCR
{
...
...
deploy/cpp_infer/
src_det
/preprocess_op.cpp
→
deploy/cpp_infer/
include
/preprocess_op.cpp
浏览文件 @
874a3262
文件已移动
deploy/cpp_infer/include/utility.h
浏览文件 @
874a3262
...
...
@@ -20,6 +20,8 @@
#include <ostream>
#include <stdlib.h>
#include <vector>
#include <sys/stat.h>
#include <dirent.h>
#include <algorithm>
#include <cstring>
...
...
@@ -34,11 +36,42 @@ namespace PaddleOCR {
class
Utility
{
public:
static
std
::
vector
<
std
::
string
>
ReadDict
(
const
std
::
string
&
path
);
static
std
::
vector
<
std
::
string
>
ReadDict
(
const
std
::
string
&
path
)
{
std
::
ifstream
in
(
path
);
std
::
string
line
;
std
::
vector
<
std
::
string
>
m_vec
;
if
(
in
)
{
while
(
getline
(
in
,
line
))
{
m_vec
.
push_back
(
line
);
}
}
else
{
std
::
cout
<<
"no such label file: "
<<
path
<<
", exit the program..."
<<
std
::
endl
;
exit
(
1
);
}
return
m_vec
;
}
static
void
VisualizeBboxes
(
const
cv
::
Mat
&
srcimg
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
);
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
)
{
cv
::
Mat
img_vis
;
srcimg
.
copyTo
(
img_vis
);
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
cv
::
Point
rook_points
[
4
];
for
(
int
m
=
0
;
m
<
boxes
[
n
].
size
();
m
++
)
{
rook_points
[
m
]
=
cv
::
Point
(
int
(
boxes
[
n
][
m
][
0
]),
int
(
boxes
[
n
][
m
][
1
]));
}
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_points
};
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"
<<
std
::
endl
;
}
template
<
class
ForwardIterator
>
inline
static
size_t
argmax
(
ForwardIterator
first
,
ForwardIterator
last
)
{
...
...
@@ -46,7 +79,36 @@ public:
}
static
void
GetAllFiles
(
const
char
*
dir_name
,
std
::
vector
<
std
::
string
>
&
all_inputs
);
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/src_det/clipper.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
此差异已折叠。
点击以展开。
deploy/cpp_infer/src_det/ocr_det.cpp
浏览文件 @
874a3262
...
...
@@ -13,6 +13,8 @@
// limitations under the License.
#include <include/ocr_det.h>
#include <include/preprocess_op.cpp>
#include <include/postprocess_op.cpp>
namespace
PaddleOCR
{
...
...
deploy/cpp_infer/src_det/postprocess_op.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <include/postprocess_op.h>
namespace
PaddleOCR
{
void
PostProcessor
::
GetContourArea
(
const
std
::
vector
<
std
::
vector
<
float
>>
&
box
,
float
unclip_ratio
,
float
&
distance
)
{
int
pts_num
=
4
;
float
area
=
0.0
f
;
float
dist
=
0.0
f
;
for
(
int
i
=
0
;
i
<
pts_num
;
i
++
)
{
area
+=
box
[
i
][
0
]
*
box
[(
i
+
1
)
%
pts_num
][
1
]
-
box
[
i
][
1
]
*
box
[(
i
+
1
)
%
pts_num
][
0
];
dist
+=
sqrtf
((
box
[
i
][
0
]
-
box
[(
i
+
1
)
%
pts_num
][
0
])
*
(
box
[
i
][
0
]
-
box
[(
i
+
1
)
%
pts_num
][
0
])
+
(
box
[
i
][
1
]
-
box
[(
i
+
1
)
%
pts_num
][
1
])
*
(
box
[
i
][
1
]
-
box
[(
i
+
1
)
%
pts_num
][
1
]));
}
area
=
fabs
(
float
(
area
/
2.0
));
distance
=
area
*
unclip_ratio
/
dist
;
}
cv
::
RotatedRect
PostProcessor
::
UnClip
(
std
::
vector
<
std
::
vector
<
float
>>
box
,
const
float
&
unclip_ratio
)
{
float
distance
=
1.0
;
GetContourArea
(
box
,
unclip_ratio
,
distance
);
ClipperLib
::
ClipperOffset
offset
;
ClipperLib
::
Path
p
;
p
<<
ClipperLib
::
IntPoint
(
int
(
box
[
0
][
0
]),
int
(
box
[
0
][
1
]))
<<
ClipperLib
::
IntPoint
(
int
(
box
[
1
][
0
]),
int
(
box
[
1
][
1
]))
<<
ClipperLib
::
IntPoint
(
int
(
box
[
2
][
0
]),
int
(
box
[
2
][
1
]))
<<
ClipperLib
::
IntPoint
(
int
(
box
[
3
][
0
]),
int
(
box
[
3
][
1
]));
offset
.
AddPath
(
p
,
ClipperLib
::
jtRound
,
ClipperLib
::
etClosedPolygon
);
ClipperLib
::
Paths
soln
;
offset
.
Execute
(
soln
,
distance
);
std
::
vector
<
cv
::
Point2f
>
points
;
for
(
int
j
=
0
;
j
<
soln
.
size
();
j
++
)
{
for
(
int
i
=
0
;
i
<
soln
[
soln
.
size
()
-
1
].
size
();
i
++
)
{
points
.
emplace_back
(
soln
[
j
][
i
].
X
,
soln
[
j
][
i
].
Y
);
}
}
cv
::
RotatedRect
res
;
if
(
points
.
size
()
<=
0
)
{
res
=
cv
::
RotatedRect
(
cv
::
Point2f
(
0
,
0
),
cv
::
Size2f
(
1
,
1
),
0
);
}
else
{
res
=
cv
::
minAreaRect
(
points
);
}
return
res
;
}
float
**
PostProcessor
::
Mat2Vec
(
cv
::
Mat
mat
)
{
auto
**
array
=
new
float
*
[
mat
.
rows
];
for
(
int
i
=
0
;
i
<
mat
.
rows
;
++
i
)
array
[
i
]
=
new
float
[
mat
.
cols
];
for
(
int
i
=
0
;
i
<
mat
.
rows
;
++
i
)
{
for
(
int
j
=
0
;
j
<
mat
.
cols
;
++
j
)
{
array
[
i
][
j
]
=
mat
.
at
<
float
>
(
i
,
j
);
}
}
return
array
;
}
std
::
vector
<
std
::
vector
<
int
>>
PostProcessor
::
OrderPointsClockwise
(
std
::
vector
<
std
::
vector
<
int
>>
pts
)
{
std
::
vector
<
std
::
vector
<
int
>>
box
=
pts
;
std
::
sort
(
box
.
begin
(),
box
.
end
(),
XsortInt
);
std
::
vector
<
std
::
vector
<
int
>>
leftmost
=
{
box
[
0
],
box
[
1
]};
std
::
vector
<
std
::
vector
<
int
>>
rightmost
=
{
box
[
2
],
box
[
3
]};
if
(
leftmost
[
0
][
1
]
>
leftmost
[
1
][
1
])
std
::
swap
(
leftmost
[
0
],
leftmost
[
1
]);
if
(
rightmost
[
0
][
1
]
>
rightmost
[
1
][
1
])
std
::
swap
(
rightmost
[
0
],
rightmost
[
1
]);
std
::
vector
<
std
::
vector
<
int
>>
rect
=
{
leftmost
[
0
],
rightmost
[
0
],
rightmost
[
1
],
leftmost
[
1
]};
return
rect
;
}
std
::
vector
<
std
::
vector
<
float
>>
PostProcessor
::
Mat2Vector
(
cv
::
Mat
mat
)
{
std
::
vector
<
std
::
vector
<
float
>>
img_vec
;
std
::
vector
<
float
>
tmp
;
for
(
int
i
=
0
;
i
<
mat
.
rows
;
++
i
)
{
tmp
.
clear
();
for
(
int
j
=
0
;
j
<
mat
.
cols
;
++
j
)
{
tmp
.
push_back
(
mat
.
at
<
float
>
(
i
,
j
));
}
img_vec
.
push_back
(
tmp
);
}
return
img_vec
;
}
bool
PostProcessor
::
XsortFp32
(
std
::
vector
<
float
>
a
,
std
::
vector
<
float
>
b
)
{
if
(
a
[
0
]
!=
b
[
0
])
return
a
[
0
]
<
b
[
0
];
return
false
;
}
bool
PostProcessor
::
XsortInt
(
std
::
vector
<
int
>
a
,
std
::
vector
<
int
>
b
)
{
if
(
a
[
0
]
!=
b
[
0
])
return
a
[
0
]
<
b
[
0
];
return
false
;
}
std
::
vector
<
std
::
vector
<
float
>>
PostProcessor
::
GetMiniBoxes
(
cv
::
RotatedRect
box
,
float
&
ssid
)
{
ssid
=
std
::
max
(
box
.
size
.
width
,
box
.
size
.
height
);
cv
::
Mat
points
;
cv
::
boxPoints
(
box
,
points
);
auto
array
=
Mat2Vector
(
points
);
std
::
sort
(
array
.
begin
(),
array
.
end
(),
XsortFp32
);
std
::
vector
<
float
>
idx1
=
array
[
0
],
idx2
=
array
[
1
],
idx3
=
array
[
2
],
idx4
=
array
[
3
];
if
(
array
[
3
][
1
]
<=
array
[
2
][
1
])
{
idx2
=
array
[
3
];
idx3
=
array
[
2
];
}
else
{
idx2
=
array
[
2
];
idx3
=
array
[
3
];
}
if
(
array
[
1
][
1
]
<=
array
[
0
][
1
])
{
idx1
=
array
[
1
];
idx4
=
array
[
0
];
}
else
{
idx1
=
array
[
0
];
idx4
=
array
[
1
];
}
array
[
0
]
=
idx1
;
array
[
1
]
=
idx2
;
array
[
2
]
=
idx3
;
array
[
3
]
=
idx4
;
return
array
;
}
float
PostProcessor
::
PolygonScoreAcc
(
std
::
vector
<
cv
::
Point
>
contour
,
cv
::
Mat
pred
)
{
int
width
=
pred
.
cols
;
int
height
=
pred
.
rows
;
std
::
vector
<
float
>
box_x
;
std
::
vector
<
float
>
box_y
;
for
(
int
i
=
0
;
i
<
contour
.
size
();
++
i
)
{
box_x
.
push_back
(
contour
[
i
].
x
);
box_y
.
push_back
(
contour
[
i
].
y
);
}
int
xmin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_x
.
begin
(),
box_x
.
end
())))),
0
,
width
-
1
);
int
xmax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_x
.
begin
(),
box_x
.
end
())))),
0
,
width
-
1
);
int
ymin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_y
.
begin
(),
box_y
.
end
())))),
0
,
height
-
1
);
int
ymax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_y
.
begin
(),
box_y
.
end
())))),
0
,
height
-
1
);
cv
::
Mat
mask
;
mask
=
cv
::
Mat
::
zeros
(
ymax
-
ymin
+
1
,
xmax
-
xmin
+
1
,
CV_8UC1
);
cv
::
Point
*
rook_point
=
new
cv
::
Point
[
contour
.
size
()];
for
(
int
i
=
0
;
i
<
contour
.
size
();
++
i
)
{
rook_point
[
i
]
=
cv
::
Point
(
int
(
box_x
[
i
])
-
xmin
,
int
(
box_y
[
i
])
-
ymin
);
}
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_point
};
int
npt
[]
=
{
int
(
contour
.
size
())};
cv
::
fillPoly
(
mask
,
ppt
,
npt
,
1
,
cv
::
Scalar
(
1
));
cv
::
Mat
croppedImg
;
pred
(
cv
::
Rect
(
xmin
,
ymin
,
xmax
-
xmin
+
1
,
ymax
-
ymin
+
1
)).
copyTo
(
croppedImg
);
float
score
=
cv
::
mean
(
croppedImg
,
mask
)[
0
];
delete
[]
rook_point
;
return
score
;
}
float
PostProcessor
::
BoxScoreFast
(
std
::
vector
<
std
::
vector
<
float
>>
box_array
,
cv
::
Mat
pred
)
{
auto
array
=
box_array
;
int
width
=
pred
.
cols
;
int
height
=
pred
.
rows
;
float
box_x
[
4
]
=
{
array
[
0
][
0
],
array
[
1
][
0
],
array
[
2
][
0
],
array
[
3
][
0
]};
float
box_y
[
4
]
=
{
array
[
0
][
1
],
array
[
1
][
1
],
array
[
2
][
1
],
array
[
3
][
1
]};
int
xmin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_x
,
box_x
+
4
)))),
0
,
width
-
1
);
int
xmax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_x
,
box_x
+
4
)))),
0
,
width
-
1
);
int
ymin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_y
,
box_y
+
4
)))),
0
,
height
-
1
);
int
ymax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_y
,
box_y
+
4
)))),
0
,
height
-
1
);
cv
::
Mat
mask
;
mask
=
cv
::
Mat
::
zeros
(
ymax
-
ymin
+
1
,
xmax
-
xmin
+
1
,
CV_8UC1
);
cv
::
Point
root_point
[
4
];
root_point
[
0
]
=
cv
::
Point
(
int
(
array
[
0
][
0
])
-
xmin
,
int
(
array
[
0
][
1
])
-
ymin
);
root_point
[
1
]
=
cv
::
Point
(
int
(
array
[
1
][
0
])
-
xmin
,
int
(
array
[
1
][
1
])
-
ymin
);
root_point
[
2
]
=
cv
::
Point
(
int
(
array
[
2
][
0
])
-
xmin
,
int
(
array
[
2
][
1
])
-
ymin
);
root_point
[
3
]
=
cv
::
Point
(
int
(
array
[
3
][
0
])
-
xmin
,
int
(
array
[
3
][
1
])
-
ymin
);
const
cv
::
Point
*
ppt
[
1
]
=
{
root_point
};
int
npt
[]
=
{
4
};
cv
::
fillPoly
(
mask
,
ppt
,
npt
,
1
,
cv
::
Scalar
(
1
));
cv
::
Mat
croppedImg
;
pred
(
cv
::
Rect
(
xmin
,
ymin
,
xmax
-
xmin
+
1
,
ymax
-
ymin
+
1
))
.
copyTo
(
croppedImg
);
auto
score
=
cv
::
mean
(
croppedImg
,
mask
)[
0
];
return
score
;
}
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
PostProcessor
::
BoxesFromBitmap
(
const
cv
::
Mat
pred
,
const
cv
::
Mat
bitmap
,
const
float
&
box_thresh
,
const
float
&
det_db_unclip_ratio
,
const
bool
&
use_polygon_score
)
{
const
int
min_size
=
3
;
const
int
max_candidates
=
1000
;
int
width
=
bitmap
.
cols
;
int
height
=
bitmap
.
rows
;
std
::
vector
<
std
::
vector
<
cv
::
Point
>>
contours
;
std
::
vector
<
cv
::
Vec4i
>
hierarchy
;
cv
::
findContours
(
bitmap
,
contours
,
hierarchy
,
cv
::
RETR_LIST
,
cv
::
CHAIN_APPROX_SIMPLE
);
int
num_contours
=
contours
.
size
()
>=
max_candidates
?
max_candidates
:
contours
.
size
();
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
;
for
(
int
_i
=
0
;
_i
<
num_contours
;
_i
++
)
{
if
(
contours
[
_i
].
size
()
<=
2
)
{
continue
;
}
float
ssid
;
cv
::
RotatedRect
box
=
cv
::
minAreaRect
(
contours
[
_i
]);
auto
array
=
GetMiniBoxes
(
box
,
ssid
);
auto
box_for_unclip
=
array
;
// end get_mini_box
if
(
ssid
<
min_size
)
{
continue
;
}
float
score
;
if
(
use_polygon_score
)
/* compute using polygon*/
score
=
PolygonScoreAcc
(
contours
[
_i
],
pred
);
else
score
=
BoxScoreFast
(
array
,
pred
);
if
(
score
<
box_thresh
)
continue
;
// start for unclip
cv
::
RotatedRect
points
=
UnClip
(
box_for_unclip
,
det_db_unclip_ratio
);
if
(
points
.
size
.
height
<
1.001
&&
points
.
size
.
width
<
1.001
)
{
continue
;
}
// end for unclip
cv
::
RotatedRect
clipbox
=
points
;
auto
cliparray
=
GetMiniBoxes
(
clipbox
,
ssid
);
if
(
ssid
<
min_size
+
2
)
continue
;
int
dest_width
=
pred
.
cols
;
int
dest_height
=
pred
.
rows
;
std
::
vector
<
std
::
vector
<
int
>>
intcliparray
;
for
(
int
num_pt
=
0
;
num_pt
<
4
;
num_pt
++
)
{
std
::
vector
<
int
>
a
{
int
(
clampf
(
roundf
(
cliparray
[
num_pt
][
0
]
/
float
(
width
)
*
float
(
dest_width
)),
0
,
float
(
dest_width
))),
int
(
clampf
(
roundf
(
cliparray
[
num_pt
][
1
]
/
float
(
height
)
*
float
(
dest_height
)),
0
,
float
(
dest_height
)))};
intcliparray
.
push_back
(
a
);
}
boxes
.
push_back
(
intcliparray
);
}
// end for
return
boxes
;
}
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
PostProcessor
::
FilterTagDetRes
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
,
float
ratio_h
,
float
ratio_w
,
cv
::
Mat
srcimg
)
{
int
oriimg_h
=
srcimg
.
rows
;
int
oriimg_w
=
srcimg
.
cols
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
root_points
;
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
boxes
[
n
]
=
OrderPointsClockwise
(
boxes
[
n
]);
for
(
int
m
=
0
;
m
<
boxes
[
0
].
size
();
m
++
)
{
boxes
[
n
][
m
][
0
]
/=
ratio_w
;
boxes
[
n
][
m
][
1
]
/=
ratio_h
;
boxes
[
n
][
m
][
0
]
=
int
(
_min
(
_max
(
boxes
[
n
][
m
][
0
],
0
),
oriimg_w
-
1
));
boxes
[
n
][
m
][
1
]
=
int
(
_min
(
_max
(
boxes
[
n
][
m
][
1
],
0
),
oriimg_h
-
1
));
}
}
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
int
rect_width
,
rect_height
;
rect_width
=
int
(
sqrt
(
pow
(
boxes
[
n
][
0
][
0
]
-
boxes
[
n
][
1
][
0
],
2
)
+
pow
(
boxes
[
n
][
0
][
1
]
-
boxes
[
n
][
1
][
1
],
2
)));
rect_height
=
int
(
sqrt
(
pow
(
boxes
[
n
][
0
][
0
]
-
boxes
[
n
][
3
][
0
],
2
)
+
pow
(
boxes
[
n
][
0
][
1
]
-
boxes
[
n
][
3
][
1
],
2
)));
if
(
rect_width
<=
4
||
rect_height
<=
4
)
continue
;
root_points
.
push_back
(
boxes
[
n
]);
}
return
root_points
;
}
}
// namespace PaddleOCR
deploy/cpp_infer/src_det/utility.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 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>
namespace
PaddleOCR
{
std
::
vector
<
std
::
string
>
Utility
::
ReadDict
(
const
std
::
string
&
path
)
{
std
::
ifstream
in
(
path
);
std
::
string
line
;
std
::
vector
<
std
::
string
>
m_vec
;
if
(
in
)
{
while
(
getline
(
in
,
line
))
{
m_vec
.
push_back
(
line
);
}
}
else
{
std
::
cout
<<
"no such label file: "
<<
path
<<
", exit the program..."
<<
std
::
endl
;
exit
(
1
);
}
return
m_vec
;
}
void
Utility
::
VisualizeBboxes
(
const
cv
::
Mat
&
srcimg
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
)
{
cv
::
Mat
img_vis
;
srcimg
.
copyTo
(
img_vis
);
for
(
int
n
=
0
;
n
<
boxes
.
size
();
n
++
)
{
cv
::
Point
rook_points
[
4
];
for
(
int
m
=
0
;
m
<
boxes
[
n
].
size
();
m
++
)
{
rook_points
[
m
]
=
cv
::
Point
(
int
(
boxes
[
n
][
m
][
0
]),
int
(
boxes
[
n
][
m
][
1
]));
}
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_points
};
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"
<<
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/src_rec/ocr_rec.cpp
浏览文件 @
874a3262
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#include <include/ocr_rec.h>
#include <include/preprocess_op.cpp>
namespace
PaddleOCR
{
...
...
deploy/cpp_infer/src_rec/preprocess_op.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
此差异已折叠。
点击以展开。
deploy/cpp_infer/src_rec/utility.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
此差异已折叠。
点击以展开。
deploy/cpp_infer/src_system/clipper.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
此差异已折叠。
点击以展开。
deploy/cpp_infer/src_system/main.cpp
浏览文件 @
874a3262
...
...
@@ -28,10 +28,8 @@
#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>
#include <gflags/gflags.h>
...
...
deploy/cpp_infer/src_system/ocr_det.cpp
浏览文件 @
874a3262
...
...
@@ -13,6 +13,8 @@
// limitations under the License.
#include <include/ocr_det.h>
#include <include/preprocess_op.cpp>
#include <include/postprocess_op.cpp>
namespace
PaddleOCR
{
...
...
deploy/cpp_infer/src_system/postprocess_op.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
此差异已折叠。
点击以展开。
deploy/cpp_infer/src_system/preprocess_op.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
此差异已折叠。
点击以展开。
deploy/cpp_infer/src_system/utility.cpp
已删除
100644 → 0
浏览文件 @
39b7263e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录