Skip to content

Commit ced6fc3

Browse files
committed
feat: Added ascii art generator program
1 parent f69fdf6 commit ced6fc3

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Ascii Art Generator/generate.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import cv2
2+
import numpy as np
3+
import sys
4+
5+
symbols_list = ["#", "-", "*", ".", "+", "o"]
6+
threshold_list = [0, 50, 100, 150, 200]
7+
8+
def print_out_ascii(array):
9+
for row in array:
10+
for e in row:
11+
print(symbols_list[int(e) % len(symbols_list)], end="")
12+
print()
13+
14+
15+
def img_to_ascii(image):
16+
height, width = image.shape
17+
new_width = int(width / 20)
18+
new_height = int(height / 40)
19+
20+
resized_image = cv2.resize(image, (new_width, new_height),)
21+
22+
thresh_image = np.zeros(resized_image.shape)
23+
24+
for i, threshold in enumerate(threshold_list):
25+
thresh_image[resized_image > threshold] = i
26+
return thresh_image
27+
28+
29+
if __name__ == "__main__":
30+
31+
if len(sys.argv) < 2:
32+
print("Image Path not specified : Using sample_image.png\n")
33+
image_path = "sample_image.png"
34+
35+
if len(sys.argv) == 2:
36+
print("Using {} as Image Path\n".format(sys.argv[1]))
37+
image_path = sys.argv[1]
38+
39+
image = cv2.imread(image_path, 0)
40+
ascii_art = img_to_ascii(image)
41+
print_out_ascii(ascii_art)
42+

0 commit comments

Comments
 (0)