Last active
June 6, 2023 01:39
-
-
Save KenjiOhtsuka/3c895ec102cce181da5ab32db60a8326 to your computer and use it in GitHub Desktop.
Convert Video to ASCII
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 | |
import numpy as np | |
cap = cv2.VideoCapture(0) | |
# replace each pixel with a character from array | |
chars = ["B", "S", "#", "&", "@", "$", "%", "*", "!", ":", "."] | |
chars = chars[::-1] | |
while True: | |
ret, frame = cap.read() | |
edframe = cv2.resize(frame, (int(frame.shape[1] / 10), int(frame.shape[0] / 10))) | |
edframe = cv2.cvtColor(edframe, cv2.COLOR_BGR2GRAY) | |
newframe = np.zeros(frame.shape, dtype=np.uint8) | |
for i1, e1 in enumerate(edframe): | |
for i2, e2 in enumerate(e1): | |
cv2.putText(newframe, chars[e2 // 25], (i2 * 10, i1 * 10), cv2.FONT_HERSHEY_PLAIN, 1, (255, 255, 255), 1, | |
cv2.LINE_AA) | |
cv2.imshow('Edited Frame', newframe) | |
k = cv2.waitKey(1) | |
# ESC key to exit | |
if k == 27: | |
break | |
cap.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment