Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc0d1ec

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 23cc72d according to the output from Autopep8. Details: None
1 parent c61e04b commit fc0d1ec

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

‎watermark on videos/app.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
import cv2
22
import numpy as np
33

4+
45
def add_watermark(input_video_path, output_video_path, watermark_path, position=(10, 10)):
56
video_capture = cv2.VideoCapture(input_video_path)
67
watermark = cv2.imread(watermark_path, cv2.IMREAD_UNCHANGED)
78
watermark_height, watermark_width, _ = watermark.shape
89
frame_width = int(video_capture.get(3))
910
frame_height = int(video_capture.get(4))
1011
fourcc = cv2.VideoWriter_fourcc(*'XVID')
11-
output_video = cv2.VideoWriter(output_video_path, fourcc, 30.0, (frame_width, frame_height))
12+
output_video = cv2.VideoWriter(
13+
output_video_path, fourcc, 30.0, (frame_width, frame_height))
1214

1315
while True:
1416
ret, frame = video_capture.read()
1517

1618
if not ret:
1719
break
1820

19-
resized_watermark = cv2.resize(watermark, (frame_width // 4, frame_height // 4))
20-
roi = frame[position[1]:position[1] + resized_watermark.shape[0], position[0]:position[0] + resized_watermark.shape[1]]
21+
resized_watermark = cv2.resize(
22+
watermark, (frame_width // 4, frame_height // 4))
23+
roi = frame[position[1]:position[1] + resized_watermark.shape[0],
24+
position[0]:position[0] + resized_watermark.shape[1]]
2125

2226
if watermark.shape[2] == 4:
2327
mask = resized_watermark[:, :, 3]
2428
mask_inv = cv2.bitwise_not(mask)
2529
img_bg = cv2.bitwise_and(roi, roi, mask=mask_inv)
26-
img_fg = cv2.bitwise_and(resized_watermark[:, :, :3], resized_watermark[:, :, :3], mask=mask)
30+
img_fg = cv2.bitwise_and(
31+
resized_watermark[:, :, :3], resized_watermark[:, :, :3], mask=mask)
2732
dst = cv2.add(img_bg, img_fg)
28-
frame[position[1]:position[1] + resized_watermark.shape[0], position[0]:position[0] + resized_watermark.shape[1]] = dst
33+
frame[position[1]:position[1] + resized_watermark.shape[0],
34+
position[0]:position[0] + resized_watermark.shape[1]] = dst
2935

3036
else:
31-
frame[position[1]:position[1] + resized_watermark.shape[0], position[0]:position[0] + resized_watermark.shape[1]] = resized_watermark[:, :, :3]
37+
frame[position[1]:position[1] + resized_watermark.shape[0], position[0]:position[0] + resized_watermark.shape[1]] = resized_watermark[:, :, :3]
3238

3339
output_video.write(frame)
3440

@@ -38,4 +44,5 @@ def add_watermark(input_video_path, output_video_path, watermark_path, position=
3844
print("Watermark added successfully!")
3945

4046

41-
add_watermark('input_video.mp4', 'output_video_with_watermark.mp4', 'watermark.png')
47+
add_watermark('input_video.mp4',
48+
'output_video_with_watermark.mp4', 'watermark.png')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /