Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
c1d19ce2
Unverified
Commit
c1d19ce2
authored
Aug 13, 2020
by
zhoujun
Committed by
GitHub
Aug 13, 2020
Browse files
Merge pull request #2 from PaddlePaddle/develop
mergepaddleocr
parents
56c6c3ae
bad9f6cd
Changes
363
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
+91
-0
ppocr/postprocess/lanms/__init__.py
ppocr/postprocess/lanms/__init__.py
+20
-0
ppocr/postprocess/lanms/__main__.py
ppocr/postprocess/lanms/__main__.py
+10
-0
ppocr/postprocess/lanms/adaptor.cpp
ppocr/postprocess/lanms/adaptor.cpp
+61
-0
No files found.
Too many changes to show.
To preserve performance only
363 of 363+
files are displayed.
Plain diff
Email patch
ppocr/postprocess/lanms/__init__.py
0 → 100644
View file @
c1d19ce2
import
subprocess
import
os
import
numpy
as
np
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
subprocess
.
call
([
'make'
,
'-C'
,
BASE_DIR
])
!=
0
:
# return value
raise
RuntimeError
(
'Cannot compile lanms: {}'
.
format
(
BASE_DIR
))
def
merge_quadrangle_n9
(
polys
,
thres
=
0.3
,
precision
=
10000
):
from
.adaptor
import
merge_quadrangle_n9
as
nms_impl
if
len
(
polys
)
==
0
:
return
np
.
array
([],
dtype
=
'float32'
)
p
=
polys
.
copy
()
p
[:,:
8
]
*=
precision
ret
=
np
.
array
(
nms_impl
(
p
,
thres
),
dtype
=
'float32'
)
ret
[:,:
8
]
/=
precision
return
ret
ppocr/postprocess/lanms/__main__.py
0 → 100644
View file @
c1d19ce2
import
numpy
as
np
from
.
import
merge_quadrangle_n9
if
__name__
==
'__main__'
:
# unit square with confidence 1
q
=
np
.
array
([
0
,
0
,
0
,
1
,
1
,
1
,
1
,
0
,
1
],
dtype
=
'float32'
)
print
(
merge_quadrangle_n9
(
np
.
array
([
q
,
q
+
0.1
,
q
+
2
])))
ppocr/postprocess/lanms/adaptor.cpp
0 → 100644
View file @
c1d19ce2
#include "pybind11/pybind11.h"
#include "pybind11/numpy.h"
#include "pybind11/stl.h"
#include "pybind11/stl_bind.h"
#include "lanms.h"
namespace
py
=
pybind11
;
namespace
lanms_adaptor
{
std
::
vector
<
std
::
vector
<
float
>>
polys2floats
(
const
std
::
vector
<
lanms
::
Polygon
>
&
polys
)
{
std
::
vector
<
std
::
vector
<
float
>>
ret
;
for
(
size_t
i
=
0
;
i
<
polys
.
size
();
i
++
)
{
auto
&
p
=
polys
[
i
];
auto
&
poly
=
p
.
poly
;
ret
.
emplace_back
(
std
::
vector
<
float
>
{
float
(
poly
[
0
].
X
),
float
(
poly
[
0
].
Y
),
float
(
poly
[
1
].
X
),
float
(
poly
[
1
].
Y
),
float
(
poly
[
2
].
X
),
float
(
poly
[
2
].
Y
),
float
(
poly
[
3
].
X
),
float
(
poly
[
3
].
Y
),
float
(
p
.
score
),
});
}
return
ret
;
}
/**
*
* \param quad_n9 an n-by-9 numpy array, where first 8 numbers denote the
* quadrangle, and the last one is the score
* \param iou_threshold two quadrangles with iou score above this threshold
* will be merged
*
* \return an n-by-9 numpy array, the merged quadrangles
*/
std
::
vector
<
std
::
vector
<
float
>>
merge_quadrangle_n9
(
py
::
array_t
<
float
,
py
::
array
::
c_style
|
py
::
array
::
forcecast
>
quad_n9
,
float
iou_threshold
)
{
auto
pbuf
=
quad_n9
.
request
();
if
(
pbuf
.
ndim
!=
2
||
pbuf
.
shape
[
1
]
!=
9
)
throw
std
::
runtime_error
(
"quadrangles must have a shape of (n, 9)"
);
auto
n
=
pbuf
.
shape
[
0
];
auto
ptr
=
static_cast
<
float
*>
(
pbuf
.
ptr
);
return
polys2floats
(
lanms
::
merge_quadrangle_n9
(
ptr
,
n
,
iou_threshold
));
}
}
PYBIND11_PLUGIN
(
adaptor
)
{
py
::
module
m
(
"adaptor"
,
"NMS"
);
m
.
def
(
"merge_quadrangle_n9"
,
&
lanms_adaptor
::
merge_quadrangle_n9
,
"merge quadrangels"
);
return
m
.
ptr
();
}
Prev
1
…
15
16
17
18
19
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment