Last active
February 7, 2024 15:33
-
-
Save sarmadgulzar/cdd9acb4553a6582fb14bcf4eae1a72d to your computer and use it in GitHub Desktop.
Launchpad Presentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip | |
from moviepy.video.VideoClip import ImageClip, TextClip | |
img = cv2.imread("input.png") | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
vid = ImageClip(img) | |
frame_height = img.shape[0] | |
frame_width = img.shape[1] | |
font_size = int(frame_width * 0.15) | |
clip_size = (frame_width, frame_height) | |
words = [ | |
{"start": 1, "end": 1.5, "word": "Hello"}, | |
{"start": 1.5, "end": 2, "word": "World!"}, | |
{"start": 2, "end": 2.5, "word": "How"}, | |
{"start": 2.5, "end": 3, "word": "are"}, | |
{"start": 3, "end": 3.5, "word": "you?"}, | |
] | |
text_clips = [] | |
for word in words: | |
text_clip = TextClip( | |
word["word"], fontsize=font_size, color="yellow", size=clip_size, align="South" | |
) | |
text_clips.append( | |
text_clip.set_start(word["start"]).set_duration(word["end"] - word["start"]) | |
) | |
final_video = CompositeVideoClip([vid] + text_clips).set_duration(4) | |
final_video.write_videofile("output.mp4", fps=25) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
filename = "input.png" | |
image = cv2.imread(filename) | |
x1, x2 = 406, 982 | |
image = image[:, x1:x2] | |
cv2.imshow(filename, image) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from deepface import DeepFace | |
filename = "input.png" | |
image = cv2.imread(filename) | |
faces = DeepFace.extract_faces( | |
image, | |
detector_backend="ssd", | |
) | |
x, y, w, h = map( | |
lambda _: faces[0]["facial_area"][_], | |
["x", "y", "w", "h"], | |
) | |
print(x, y, w, h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
filename = "input.png" | |
image = cv2.imread(filename) | |
cv2.imshow(filename, image) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
filename = "input.mp4" | |
cap = cv2.VideoCapture(filename) | |
while True: | |
_, frame = cap.read() | |
cv2.imshow("Frame", frame) | |
if cv2.waitKey(25) & 0xFF == ord("q"): | |
break | |
cap.release() | |
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
filename = "input.png" | |
image = cv2.imread(filename) | |
x, y, w, h = (621, 293, 147, 181) | |
cv2.rectangle( | |
image, | |
pt1=(x, y), | |
pt2=(x + w, y + h), | |
color=(0, 255, 0), | |
thickness=2, | |
) | |
cv2.imshow(filename, image) | |
cv2.waitKey(0) | |
cv2.imwrite("output.png", image) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment