]> Skullheadx's Git Forge - text-art.git/commitdiff
text to art finished
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sat, 24 Dec 2022 07:28:06 +0000 (02:28 -0500)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sat, 24 Dec 2022 07:28:06 +0000 (02:28 -0500)
frames/frame0.png
frames/frame1.png
frames/frame2.jpg [deleted file]
main.py
output/output.mp4 [deleted file]
setup.py
text_art.py
text_art_frames/frame0.png [deleted file]
text_art_frames/frame1.png [deleted file]
text_art_frames/frame2.jpg [deleted file]
video.py

index 1ab44eb19ab05e362a1a225424b2149d728b9c76..9822c06ec485e155f78c067a36328d1e78ab0c27 100644 (file)
Binary files a/frames/frame0.png and b/frames/frame0.png differ
index 2594619757bca3caed089b57b4effc4c3a57f094..8ff83d0d3a3f8a430bb73f677865c8c295f3f202 100644 (file)
Binary files a/frames/frame1.png and b/frames/frame1.png differ
diff --git a/frames/frame2.jpg b/frames/frame2.jpg
deleted file mode 100644 (file)
index 81c750d..0000000
Binary files a/frames/frame2.jpg and /dev/null differ
diff --git a/main.py b/main.py
index 0bfec3c5d65560c19de4b6ae7f4677989d28caeb..a037e0d60733feab353c26eb41d7a80e4f101eef 100644 (file)
--- a/main.py
+++ b/main.py
@@ -8,13 +8,12 @@ from text_art import text_art
 def main() -> None:
     # file_name = input("Enter name of file: ")
     file_name = input_filename
-    # extract_frames(file_name)
+    extract_frames(file_name)
+    frames = get_frames(frames_path)
+    for image in frames:
+        text_art(image)
 
-    frames = get_frames()
-
-    output_frames = [text_art(image) for image in frames]
-
-    # to_video(output_frames)
+    to_video(text_art_frames_path,get_frames(text_art_frames_path))
 
 
 if __name__ == '__main__':
diff --git a/output/output.mp4 b/output/output.mp4
deleted file mode 100644 (file)
index da8e2bf..0000000
Binary files a/output/output.mp4 and /dev/null differ
index 8b90d52aa6f8d22c6abf2b74395b73a53a0d2172..cf7e86b685cfe768ec463c5cd48ee039e0d2941d 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -2,12 +2,12 @@ import cv2
 import os
 import numpy as np
 import math
-
+from moviepy.editor import *
 
 frames_path = "C:/Users/admon/Documents/GitHub/text-art/frames/"
 text_art_frames_path = "C:/Users/admon/Documents/GitHub/text-art/text_art_frames/"
 output_filename = "output/output.mp4"
-input_filename = "input/donut.mp4"
+input_filename = "input/Rick Astley - Never Gonna Give You Up (Official Music Video).mp4"
 
 BLACK = (0,0,0)
 WHITE = (255,255,255)
index 68dcc472254921ea36807fa7e631e2c056e88928..7c0d78e6fd1f04f804423f71578883fa2ca593a9 100644 (file)
@@ -1,47 +1,74 @@
 from setup import *
 
-def text_art(path): # 600, 800
-    image = cv2.imread(os.path.join(frames_path,path))
+
+def text_art(path):  # 600, 800
+    image = cv2.imread(os.path.join(frames_path, path), 0)
     """
 alpha 1  beta 0      --> no change  
 0 < alpha < 1        --> lower contrast  
 alpha > 1            --> higher contrast  
 -127 < beta < +127   --> good range for brightness values
     """
-    alpha = 2
-    beta = 127
-    image = alpha*image + beta
-    scale = 3
-    density = "Ñ@#W$9876543210?!abc;:+=-,._       "
-    # density = '     .:-i|=+%O#@'
+    # alpha =2
+    # beta = 127
+    # image = alpha*image + beta
+
+    width, height = np.array(image).shape
+    new_image = np.zeros((width, height), np.uint8)
+    # print(width, height, new_image.shape)
+
+    # density = "Ñ@#W$9876543210?!abc;:+=-,._       "
+    density = '     .:-i|=+%O#@'
     # density = density[::-1]
     density_length = len(density)
 
-    rows,cols,_ = image.shape
-    output = []
-    for i in range(0,rows,scale):
-        line = ""
-        for j in range(0,cols, scale):
-            avg = np.average(image[i,j])
-            avg = min(avg * 2, 255)
-            density_index = math.floor(find_index(avg, 0, 255, 0, density_length - 1))
-            line += density[density_index]
-        output.append(line)
-    cv2.rectangle(image, (0,0), (cols,rows), BLACK, -1)
-    # cv2.imwrite(os.path.join(text_art_frames_path, path), image)
-
     font = cv2.FONT_HERSHEY_COMPLEX_SMALL
-    font_size = 0.9
+
+    """
+    density = '     .:-i|=+%O#@'
+    scale = 10
+    font_size = 1
     thick = 1
-    font_color = WHITE
-    for i,text in enumerate(output[::-1]):
-        (text_width, text_height) = cv2.getTextSize(text, font, font_size, thick)[0]
-        text_height += i * scale
-        mask = np.zeros((text_height, text_width), dtype=np.uint8)
-        mask = cv2.putText(mask,text,(10,scale),font,font_size,font_color,thick,cv2.LINE_AA)
-        mask = cv2.resize(mask, (image.shape[1], text_height))
-        mask = cv2.merge((mask, mask, mask))
-        if image[-text_height:, :, :].size == mask.size:
-            image[-text_height:, :, :] = cv2.bitwise_or(image[-text_height:, :, :], mask)
-        cv2.imwrite(os.path.join(text_art_frames_path, path), image)
+    
+    density = '     .:-i|=+%O#@'
+    scale = 20
+    font_size =1
+    thick = 3
+    """
+
+    scale = 10
+    font_size = 1
+    thick = 1
+    # cv2.rectangle(image, (0,0), (height,width), BLACK, -1)
+    # cv2.imwrite(os.path.join(text_art_frames_path, path), image)
+
+    # line = ""
+    for index, i in np.ndenumerate(image):
+        y, x = index
+        if (x % scale) or (y % scale):
+            continue
+        # if (x+y) % 25 != 0:
+        #     continue
+        # for k in np.nditer(i):
+
+        density_index = math.floor(find_index(image[index], 0, 255, 0, density_length - 1))
+        text = density[density_index]
+        font_color = (255, 255, 255, int(image[index]))  #
+        # line += text
+
+        # (text_width, text_height) = cv2.getTextSize(text, font, font_size, thick)[0]
+        # text_height += y * scale
+        cv2.putText(new_image, text, (x, y), font, font_size, font_color, thick, cv2.LINE_AA)
+
+        # if y == 0 and x > 0:
+        #     line += '\n'
+        #     pass
+
+    # print(line)
+
+    # image[-text_height:,:] = cv2.bitwise_or(image[-text_height:,:], mask)
+    #
+    cv2.imwrite(os.path.join(text_art_frames_path, path), new_image)
+    # cv2.imshow('Grayscale Image', new_image)
+    # cv2.waitKey(0)
     return path
diff --git a/text_art_frames/frame0.png b/text_art_frames/frame0.png
deleted file mode 100644 (file)
index 1ba5655..0000000
Binary files a/text_art_frames/frame0.png and /dev/null differ
diff --git a/text_art_frames/frame1.png b/text_art_frames/frame1.png
deleted file mode 100644 (file)
index b62c123..0000000
Binary files a/text_art_frames/frame1.png and /dev/null differ
diff --git a/text_art_frames/frame2.jpg b/text_art_frames/frame2.jpg
deleted file mode 100644 (file)
index 95cf9b0..0000000
Binary files a/text_art_frames/frame2.jpg and /dev/null differ
index 780626e4dc550579825b312bd242b8244f6077c5..f69f8c34a1a211ab4fb04bac6fbd7b1c3f0b199a 100644 (file)
--- a/video.py
+++ b/video.py
@@ -22,19 +22,25 @@ def extract_frames(path: str) -> None:
     cv2.destroyAllWindows()
 
 
-def to_video(frames: list) -> None:
-    height, width, layers = cv2.imread(os.path.join(frames_path,frames[0])).shape
+def to_video(path: str, frames: list) -> None:
+    height, width, layers = cv2.imread(os.path.join(path, frames[0])).shape
     fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
-    writer = cv2.VideoWriter(output_filename, fourcc, 33, (width, height))
+    writer = cv2.VideoWriter(output_filename, fourcc, 25, (width, height))
     for frame in frames:
-        writer.write(cv2.imread(os.path.join(frames_path,frame)))
+        writer.write(cv2.imread(os.path.join(path, frame)))
 
     cv2.destroyAllWindows()
     writer.release()
 
-def get_frames():
+    # adding audio
+    clip = VideoFileClip(output_filename)
+    audio_clip = AudioFileClip(input_filename)
+    clip.audio = audio_clip
+    clip.write_videofile("output/output1.mp4")
+def get_frames(path):
+    # return ["frame2.png"]
     frames = []
-    for root, dirs, files in os.walk(frames_path):
+    for root, dirs, files in os.walk(path):
         for file in files:
             frames.append(file)
     frames.sort(key=get_number)