1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
from setup import *
def add_text(grayscale: int, x: int, y: int, new_image: np.ndarray) -> None:
density_index = math.floor(find_index(grayscale, 0, 255, 0, density_length - 1))
text = density[density_index]
font_color = (255, 255, 255, int(grayscale))
cv2.putText(new_image, text, (x, y), font, font_size, font_color, thick, cv2.LINE_AA)
def text_art_video(path: str) -> str:
image = cv2.imread(os.path.join(frames_path, path), 0)
width, height = np.array(image).shape
new_image = np.zeros((width, height), np.uint8)
for index, i in np.ndenumerate(image):
y, x = index
if (x % scale) or (y % scale):
continue
add_text(image[index], x, y, new_image)
cv2.imwrite(os.path.join(text_art_frames_path, path), new_image)
return path
def text_art_image(path: str) -> None:
image = cv2.imread(os.path.join(frames_path, path), 0) # grayscale image
line = ""
for index, i in np.ndenumerate(image):
y, x = index
if (x % scale) or (y % scale):
continue
line += density[math.floor(find_index(image[index], 0, 255, 0, density_length - 1))]
if x == 0 and y > 0:
line += '\n'
# Write to txt file
with open(os.path.join(text_art_txts_path, f"frame{get_number(path)}.txt"), "w") as f:
f.write(line)
|