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
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)