forked from sjqtentacles/Video-To-Ascii-in-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoToAscii.py
50 lines (39 loc) · 1.11 KB
/
videoToAscii.py
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
42
43
44
45
46
47
48
49
50
import cv2
def transform(img):
transformedAscii = []
for i in img:
temp = []
for j in i:
temp.append(asciiToNum[j])
transformedAscii.append(temp)
return transformedAscii
def setupAsciiMapping():
asciiToNum = {}
characterSet = list(' ..,,::;;ii11ttffLL;;::..ii11ttL')
#characterSet = list(' .....//ii11tt ... ii11ttL')
#characterSet = list((' '*2)+('n'*2)+('n'*1)+('/'*3)+('.'*2)+(' '*23))
#characterSet = list((' '*2)+('n'*2)+('n'*1)+('/'*3)+('.'*6)+(' '*23))
#characterSet = characterSet[::-1]
for i in range(26):
for j in range(10):
asciiToNum[i*10+j]=characterSet[i]
return asciiToNum
def arrayToString(arr):
ascii = ''
for i in transformedAscii:
ascii+= ' '.join(i)
ascii+='\n'
return ascii
asciiToNum = setupAsciiMapping()
width,height = 80,60
cap = cv2.VideoCapture(0)
ret = cap.set(3,width)
ret = cap.set(4,height)
while True:
ret,frame = cap.read()
img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
transformedAscii = transform(img)
print arrayToString(transformedAscii)
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()