-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (45 loc) · 942 Bytes
/
main.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
51
52
53
# import cv2
import sys
from PIL import Image
from color import *
import scipy.misc as sm
from util import getArgs,errorFileNotFound,help,errorFileArgNotFound
cv=False;
#add support for cv2
def usePIL(file,size):
try:
img=Image.open(file)
except IOError:
errorFileNotFound()
img = np.array(Image.open(file))
img = sm.imresize(img,size)
l=img.shape
return img
def useCV2(file,size):
global cv
cv=True
try:
img=cv2.imread(file)
except IOError:
errorFileNotFound()
img=cv2.resize(img, size)
return img
file,h,w=getArgs()
size=(int(h),int(w))
# check if cv2 is available
try:
import cv2
img=useCV2(file,size)
except ImportError:
img=usePIL(file,size)
# exit(0);
if not file:
errorFileArgNotFound()
print(file,size)
print(img[1,2])
# exit(0)
for i in range(0,size[0]):
for j in range(0,size[1]):
code=str(output(rgb(img[i][j])))
sys.stdout.write("\u001b[38;5;"+code+"m \033[;7m")
print(u"\u001b[42;1m")