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 c14cbfa

Browse files
committed
adding code for watermark
1 parent 022bf32 commit c14cbfa

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

‎Video_Watermark/watermark.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from cv2 import cv2
2+
3+
# take the input video
4+
cap = cv2.VideoCapture('videos/input.mp4')
5+
6+
# We need to set resolutions.
7+
# so, convert them from float to integer.
8+
frame_width = int(cap.get(3))
9+
frame_height = int(cap.get(4))
10+
11+
size = (frame_width, frame_height)
12+
13+
# get the frame rate of the input video
14+
fps = cap.get(cv2.CAP_PROP_FPS)
15+
print("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))
16+
17+
# Below VideoWriter object will create
18+
# a frame of above defined The output
19+
# is stored in 'videos/output' file.
20+
result = cv2.VideoWriter('videos/output.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, size)
21+
22+
print("processing started...")
23+
24+
# continue till the video is not over...
25+
while(cap.isOpened()):
26+
27+
# Capture frame-by-frame from the video
28+
ret, frame = cap.read()
29+
if ret == True:
30+
31+
# describe the type of font to be used.
32+
font = cv2.FONT_HERSHEY_SIMPLEX
33+
34+
# Use putText() method for inserting text on video
35+
# Parameters:-
36+
# frame: current running frame of the video.
37+
# Text: The text string to be inserted.
38+
# org: bottom-left corner of the text string
39+
# font: the type of font to be used.
40+
# color: the colour of the font.
41+
# thickness: the thickness of the font
42+
43+
cv2.putText(frame, 'HELLO WORLD', (50, 50), font, 1, (0, 255, 255), 2, cv2.LINE_4)
44+
# write in the output file
45+
result.write(frame)
46+
47+
# Display the resulting frame
48+
cv2.imshow('video', frame)
49+
50+
# creating 'q' as the quit button for the video
51+
if cv2.waitKey(1) & 0xFF == ord('q'):
52+
break
53+
else:
54+
break
55+
56+
57+
# release the cap object
58+
cap.release()
59+
result.release()
60+
61+
# close all windows
62+
cv2.destroyAllWindows()
63+
64+
print("Video successfully saved inside the videos folder")

0 commit comments

Comments
(0)

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