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
d8dfdc92
Commit
d8dfdc92
authored
Feb 23, 2022
by
zhiminzhang0830
Browse files
use Polygon from shapely
parent
3352ddb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
20 deletions
+18
-20
ppocr/data/imaug/fce_aug.py
ppocr/data/imaug/fce_aug.py
+5
-5
ppocr/utils/poly_nms.py
ppocr/utils/poly_nms.py
+13
-15
No files found.
ppocr/data/imaug/fce_aug.py
View file @
d8dfdc92
...
@@ -18,7 +18,7 @@ https://github.com/open-mmlab/mmocr/blob/main/mmocr/datasets/pipelines/transform
...
@@ -18,7 +18,7 @@ https://github.com/open-mmlab/mmocr/blob/main/mmocr/datasets/pipelines/transform
import
numpy
as
np
import
numpy
as
np
from
PIL
import
Image
,
ImageDraw
from
PIL
import
Image
,
ImageDraw
import
cv2
import
cv2
import
Polygon
as
plg
from
shapely.geometry
import
Polygon
import
math
import
math
from
ppocr.utils.poly_nms
import
poly_intersection
from
ppocr.utils.poly_nms
import
poly_intersection
...
@@ -129,16 +129,16 @@ class RandomCropFlip:
...
@@ -129,16 +129,16 @@ class RandomCropFlip:
pts
=
np
.
stack
([[
xmin
,
xmax
,
xmax
,
xmin
],
pts
=
np
.
stack
([[
xmin
,
xmax
,
xmax
,
xmin
],
[
ymin
,
ymin
,
ymax
,
ymax
]]).
T
.
astype
(
np
.
int32
)
[
ymin
,
ymin
,
ymax
,
ymax
]]).
T
.
astype
(
np
.
int32
)
pp
=
plg
.
Polygon
(
pts
)
pp
=
Polygon
(
pts
)
fail_flag
=
False
fail_flag
=
False
for
polygon
,
ignore_tag
in
zip
(
polygons
,
ignore_tags
):
for
polygon
,
ignore_tag
in
zip
(
polygons
,
ignore_tags
):
ppi
=
plg
.
Polygon
(
polygon
.
reshape
(
-
1
,
2
))
ppi
=
Polygon
(
polygon
.
reshape
(
-
1
,
2
))
ppiou
,
_
=
poly_intersection
(
ppi
,
pp
)
ppiou
,
_
=
poly_intersection
(
ppi
,
pp
)
if
np
.
abs
(
ppiou
-
float
(
ppi
.
area
()
))
>
self
.
epsilon
and
\
if
np
.
abs
(
ppiou
-
float
(
ppi
.
area
))
>
self
.
epsilon
and
\
np
.
abs
(
ppiou
)
>
self
.
epsilon
:
np
.
abs
(
ppiou
)
>
self
.
epsilon
:
fail_flag
=
True
fail_flag
=
True
break
break
elif
np
.
abs
(
ppiou
-
float
(
ppi
.
area
()
))
<
self
.
epsilon
:
elif
np
.
abs
(
ppiou
-
float
(
ppi
.
area
))
<
self
.
epsilon
:
polys_new
.
append
(
polygon
)
polys_new
.
append
(
polygon
)
ignore_tags_new
.
append
(
ignore_tag
)
ignore_tags_new
.
append
(
ignore_tag
)
else
:
else
:
...
...
ppocr/utils/poly_nms.py
View file @
d8dfdc92
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
# limitations under the License.
# limitations under the License.
import
numpy
as
np
import
numpy
as
np
import
Polygon
as
plg
from
shapely.geometry
import
Polygon
def
points2polygon
(
points
):
def
points2polygon
(
points
):
...
@@ -33,7 +33,7 @@ def points2polygon(points):
...
@@ -33,7 +33,7 @@ def points2polygon(points):
assert
(
points
.
size
%
2
==
0
)
and
(
points
.
size
>=
8
)
assert
(
points
.
size
%
2
==
0
)
and
(
points
.
size
>=
8
)
point_mat
=
points
.
reshape
([
-
1
,
2
])
point_mat
=
points
.
reshape
([
-
1
,
2
])
return
plg
.
Polygon
(
point_mat
)
return
Polygon
(
point_mat
)
def
poly_intersection
(
poly_det
,
poly_gt
):
def
poly_intersection
(
poly_det
,
poly_gt
):
...
@@ -46,13 +46,11 @@ def poly_intersection(poly_det, poly_gt):
...
@@ -46,13 +46,11 @@ def poly_intersection(poly_det, poly_gt):
Returns:
Returns:
intersection_area (float): The intersection area between two polygons.
intersection_area (float): The intersection area between two polygons.
"""
"""
assert
isinstance
(
poly_det
,
plg
.
Polygon
)
assert
isinstance
(
poly_det
,
Polygon
)
assert
isinstance
(
poly_gt
,
plg
.
Polygon
)
assert
isinstance
(
poly_gt
,
Polygon
)
poly_inter
=
poly_det
&
poly_gt
poly_inter
=
poly_det
.
buffer
(
0.001
)
&
poly_gt
.
buffer
(
0.001
)
if
len
(
poly_inter
)
==
0
:
return
poly_inter
.
area
,
poly_inter
return
0
,
poly_inter
return
poly_inter
.
area
(),
poly_inter
def
poly_union
(
poly_det
,
poly_gt
):
def
poly_union
(
poly_det
,
poly_gt
):
...
@@ -65,11 +63,11 @@ def poly_union(poly_det, poly_gt):
...
@@ -65,11 +63,11 @@ def poly_union(poly_det, poly_gt):
Returns:
Returns:
union_area (float): The union area between two polygons.
union_area (float): The union area between two polygons.
"""
"""
assert
isinstance
(
poly_det
,
plg
.
Polygon
)
assert
isinstance
(
poly_det
,
Polygon
)
assert
isinstance
(
poly_gt
,
plg
.
Polygon
)
assert
isinstance
(
poly_gt
,
Polygon
)
area_det
=
poly_det
.
area
()
area_det
=
poly_det
.
area
area_gt
=
poly_gt
.
area
()
area_gt
=
poly_gt
.
area
area_inters
,
_
=
poly_intersection
(
poly_det
,
poly_gt
)
area_inters
,
_
=
poly_intersection
(
poly_det
,
poly_gt
)
return
area_det
+
area_gt
-
area_inters
return
area_det
+
area_gt
-
area_inters
...
@@ -114,8 +112,8 @@ def poly_iou(poly_det, poly_gt):
...
@@ -114,8 +112,8 @@ def poly_iou(poly_det, poly_gt):
Returns:
Returns:
iou (float): The IOU between two polygons.
iou (float): The IOU between two polygons.
"""
"""
assert
isinstance
(
poly_det
,
plg
.
Polygon
)
assert
isinstance
(
poly_det
,
Polygon
)
assert
isinstance
(
poly_gt
,
plg
.
Polygon
)
assert
isinstance
(
poly_gt
,
Polygon
)
area_inters
,
_
=
poly_intersection
(
poly_det
,
poly_gt
)
area_inters
,
_
=
poly_intersection
(
poly_det
,
poly_gt
)
area_union
=
poly_union
(
poly_det
,
poly_gt
)
area_union
=
poly_union
(
poly_det
,
poly_gt
)
if
area_union
==
0
:
if
area_union
==
0
:
...
@@ -142,4 +140,4 @@ def poly_nms(polygons, threshold):
...
@@ -142,4 +140,4 @@ def poly_nms(polygons, threshold):
remove_index
=
np
.
where
(
iou_list
>
threshold
)
remove_index
=
np
.
where
(
iou_list
>
threshold
)
index
=
np
.
delete
(
index
,
remove_index
)
index
=
np
.
delete
(
index
,
remove_index
)
return
keep_poly
return
keep_poly
\ No newline at end of file
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