From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Sat, 24 Dec 2022 07:28:06 +0000 (-0500) Subject: text to art finished X-Git-Url: http://git.skullheadx.com/index.css?a=commitdiff_plain;h=42c9eae0ba4db9a9453c4aa9465a339888902a2e;p=text-art.git text to art finished --- diff --git a/frames/frame0.png b/frames/frame0.png index 1ab44eb..9822c06 100644 Binary files a/frames/frame0.png and b/frames/frame0.png differ diff --git a/frames/frame1.png b/frames/frame1.png index 2594619..8ff83d0 100644 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 index 81c750d..0000000 Binary files a/frames/frame2.jpg and /dev/null differ diff --git a/main.py b/main.py index 0bfec3c..a037e0d 100644 --- 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 index da8e2bf..0000000 Binary files a/output/output.mp4 and /dev/null differ diff --git a/setup.py b/setup.py index 8b90d52..cf7e86b 100644 --- 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) diff --git a/text_art.py b/text_art.py index 68dcc47..7c0d78e 100644 --- a/text_art.py +++ b/text_art.py @@ -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 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 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 index 95cf9b0..0000000 Binary files a/text_art_frames/frame2.jpg and /dev/null differ diff --git a/video.py b/video.py index 780626e..f69f8c3 100644 --- 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)