import
cv2
import
numpy as np
background
=
cv2.imread(
'Assets/img1.jpg'
)
overlay_image
=
cv2.imread(
'Assets/overlay3.png'
)
overlay_image
=
cv2.resize(overlay_image, (
1000
,
1000
))
h, w
=
overlay_image.shape[:
2
]
shapes
=
np.zeros_like(background, np.uint8)
shapes[background.shape[
0
]
-
h:, background.shape[
1
]
-
w:]
=
overlay_image
mask
=
shapes.astype(
bool
)
for
alpha
in
np.arange(
0
,
1.1
,
0.1
)[::
-
1
]:
bg_img
=
background.copy()
bg_img[mask]
=
cv2.addWeighted(bg_img,
1
-
alpha, shapes,
alpha,
0
)[mask]
cv2.putText(bg_img, f
'Alpha: {round(alpha,1)}'
, (
50
,
200
),
cv2.FONT_HERSHEY_PLAIN,
8
, (
200
,
200
,
200
),
7
)
bg_img
=
cv2.resize(bg_img, (
630
,
630
))
cv2.imshow(
'Final Overlay'
, bg_img)
cv2.waitKey(
0
)