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
605bf838
Unverified
Commit
605bf838
authored
Jul 04, 2021
by
zhoujun
Committed by
GitHub
Jul 04, 2021
Browse files
fix bug in copy_paste (#3245)
* fix bug in copy_paste * limit paste img not outside
parent
9d44728d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
ppocr/data/imaug/copy_paste.py
ppocr/data/imaug/copy_paste.py
+6
-4
No files found.
ppocr/data/imaug/copy_paste.py
View file @
605bf838
...
@@ -73,11 +73,14 @@ class CopyPaste(object):
...
@@ -73,11 +73,14 @@ class CopyPaste(object):
box_img_pil
=
Image
.
fromarray
(
box_img
).
convert
(
'RGBA'
)
box_img_pil
=
Image
.
fromarray
(
box_img
).
convert
(
'RGBA'
)
src_w
,
src_h
=
src_img
.
size
src_w
,
src_h
=
src_img
.
size
box_w
,
box_h
=
box_img_pil
.
size
box_w
,
box_h
=
box_img_pil
.
size
if
box_w
>
src_w
or
box_h
>
src_h
:
return
src_img
,
None
angle
=
np
.
random
.
randint
(
0
,
360
)
angle
=
np
.
random
.
randint
(
0
,
360
)
box
=
np
.
array
([[[
0
,
0
],
[
box_w
,
0
],
[
box_w
,
box_h
],
[
0
,
box_h
]]])
box
=
np
.
array
([[[
0
,
0
],
[
box_w
,
0
],
[
box_w
,
box_h
],
[
0
,
box_h
]]])
box
=
rotate_bbox
(
box_img
,
box
,
angle
)[
0
]
box
=
rotate_bbox
(
box_img
,
box
,
angle
)[
0
]
box_img_pil
=
box_img_pil
.
rotate
(
angle
,
expand
=
1
)
box_w
,
box_h
=
box_img_pil
.
width
,
box_img_pil
.
height
if
src_w
-
box_w
<
0
or
src_h
-
box_h
<
0
:
return
src_img
,
None
paste_x
,
paste_y
=
self
.
select_coord
(
src_polys
,
box
,
src_w
-
box_w
,
paste_x
,
paste_y
=
self
.
select_coord
(
src_polys
,
box
,
src_w
-
box_w
,
src_h
-
box_h
)
src_h
-
box_h
)
...
@@ -85,7 +88,6 @@ class CopyPaste(object):
...
@@ -85,7 +88,6 @@ class CopyPaste(object):
return
src_img
,
None
return
src_img
,
None
box
[:,
0
]
+=
paste_x
box
[:,
0
]
+=
paste_x
box
[:,
1
]
+=
paste_y
box
[:,
1
]
+=
paste_y
box_img_pil
=
box_img_pil
.
rotate
(
angle
,
expand
=
1
)
r
,
g
,
b
,
A
=
box_img_pil
.
split
()
r
,
g
,
b
,
A
=
box_img_pil
.
split
()
src_img
.
paste
(
box_img_pil
,
(
paste_x
,
paste_y
),
mask
=
A
)
src_img
.
paste
(
box_img_pil
,
(
paste_x
,
paste_y
),
mask
=
A
)
...
@@ -105,7 +107,7 @@ class CopyPaste(object):
...
@@ -105,7 +107,7 @@ class CopyPaste(object):
num_poly_in_rect
=
0
num_poly_in_rect
=
0
for
poly
in
src_polys
:
for
poly
in
src_polys
:
if
not
is_poly_outside_rect
(
poly
,
xm
ax
1
,
ymin1
,
if
not
is_poly_outside_rect
(
poly
,
xm
in
1
,
ymin1
,
xmax1
-
xmin1
,
ymax1
-
ymin1
):
xmax1
-
xmin1
,
ymax1
-
ymin1
):
num_poly_in_rect
+=
1
num_poly_in_rect
+=
1
break
break
...
...
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