Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Code Computer Vision
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PolySTAR
RoboMaster
Computer Vision
Code Computer Vision
Commits
2f133a45
Commit
2f133a45
authored
5 years ago
by
Guillaume Vergnolle
Committed by
Mathieu Beligon
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
superposition solved. scale and position randomized
parent
ab52cee5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
robots-at-runes/research/constants.py
+2
-0
2 additions, 0 deletions
robots-at-runes/research/constants.py
robots-at-runes/research/superposition.py
+39
-20
39 additions, 20 deletions
robots-at-runes/research/superposition.py
with
41 additions
and
20 deletions
robots-at-runes/research/constants.py
+
2
−
0
View file @
2f133a45
FACT_RESIZE
=
1
# Facteur de redimensionnement. La taille de l'image sera
# divisée ou multipliée par ce chiffre au maximum
\ No newline at end of file
This diff is collapsed.
Click to expand it.
robots-at-runes/research/superposition.py
+
39
−
20
View file @
2f133a45
...
...
@@ -2,26 +2,47 @@ import numpy as np
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
import
cv2
import
random
as
rd
import
constants
as
cst
threshold
=
100
percent_scale
=
np
.
round
((
2
*
rd
.
random
())
-
1
,
3
)
def
superimpose
(
img1
,
img2
,
mask
)
:
def
superimpose
(
img1
,
img2
,
mask
):
"""
Superimpose two pictures based on a mask. The two pictures
must have the same shape.
:param img1: first picture
:param img2: second picture
:param mask: mask applied on both pictures.
'
True
'
values will be applied on first picture
:param mask: mask applied on both pictures. Values between 0 and 255
:return: Composition
"""
dst_shape
=
img1
.
shape
composition
=
np
.
\
zeros
(
dst_shape
,
dtype
=
np
.
uint8
)
for
i
in
range
(
dst_shape
[
2
])
:
composition
[:,:,
i
]
=
mask
*
img1
[:,:,
i
]
+
~
mask
*
img2
[:,:,
i
]
return
composition
img1f
=
img1
.
astype
(
np
.
float
)
img2f
=
img2
.
astype
(
np
.
float
)
mix
=
np
.
zeros
(
dst_shape
,
dtype
=
np
.
uint8
)
for
i
in
range
(
dst_shape
[
2
]):
mix
[:,
:,
i
]
=
((
~
mask
*
img1f
[:,
:,
i
]
+
mask
*
img2f
[:,
:,
i
])
/
255
).
astype
(
np
.
uint8
)
return
mix
def
get_subset_shapes
(
img_extract
,
hs
,
ws
):
he
,
we
,
_
=
img_extract
.
shape
delta_h
=
he
-
hs
delta_w
=
we
-
ws
h_start
=
int
(
rd
.
random
()
*
delta_h
)
w_start
=
int
(
rd
.
random
()
*
delta_w
)
return
img_extract
[
h_start
:
h_start
+
hs
,
w_start
:
w_start
+
ws
,
:],
h_start
,
w_start
def
reshape_percentage
(
img_base
,
percent
):
intensity
=
1
+
abs
(
percent
)
*
cst
.
FACT_RESIZE
h
,
w
,
_
=
img_base
.
shape
if
percent
<
0
:
h_dest
,
w_dest
=
int
(
h
/
intensity
),
int
(
w
/
intensity
)
else
:
h_dest
,
w_dest
=
h
*
int
(
intensity
),
w
*
int
(
intensity
)
return
cv2
.
resize
(
img_base
,
(
w_dest
,
h_dest
),
interpolation
=
cv2
.
INTER_AREA
)
background
=
cv2
.
imread
(
"
images_sup/back1.jpg
"
)
...
...
@@ -29,22 +50,20 @@ background = cv2.cvtColor(background, cv2.COLOR_BGR2RGB)
logo
=
cv2
.
imread
(
"
images_sup/logo.png
"
,
cv2
.
IMREAD_UNCHANGED
)
logo
=
cv2
.
cvtColor
(
logo
,
cv2
.
COLOR_BGRA2RGBA
)
h
,
w
,
_
=
background
.
shape
logo
=
cv2
.
resize
(
logo
,
(
w
,
h
),
interpolation
=
cv2
.
INTER_AREA
)
mask_alpha
=
(
logo
[:,:,
3
]
<
threshold
)
logo
=
reshape_percentage
(
logo
,
percent_scale
)
mask_alpha
=
logo
[:,
:,
3
]
logo
=
cv2
.
cvtColor
(
logo
,
cv2
.
COLOR_RGBA2RGB
)
hs
,
ws
,
_
=
logo
.
shape
# logo = cv2.imread("ima
ge
s
_su
p/logo.png"
)
# logo = cv2.cvtColor(logo, cv2.COLOR_BGR2RGB
)
background_subset
,
h_start
,
w_start
=
ge
t
_su
bset_shapes
(
background
,
hs
,
ws
)
composition_subset
=
superimpose
(
background_subset
,
logo
,
mask_alpha
)
composition
=
superimpose
(
background
,
logo
,
mask_alpha
)
composition
=
background
.
copy
()
composition
[
h_start
:
h_start
+
hs
,
w_start
:
w_start
+
ws
,
:]
=
composition_subset
plt
.
imshow
(
background
)
plt
.
show
()
plt
.
imshow
(
logo
)
plt
.
show
()
plt
.
imshow
(
composition
)
plt
.
show
()
\ No newline at end of file
plt
.
show
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment