forked from cilame/any-whim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pic2xls.py
52 lines (42 loc) · 1.16 KB
/
pic2xls.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
# # py2
# import cv2
# from numpy import *
# from xlsxwriter.workbook import Workbook
# ROUND = 7.
# img = cv2.imread('123.jpg')
# y,x,ch = img.shape
# img = cv2.resize(img,(y/3,x/3))
# y,x,ch = img.shape
# t = Workbook('pic.xlsx')
# ts = t.add_worksheet()
# ts.set_default_row(height=1.8)
# ts.set_column(0,5000,.2)
# s = [(i,j) for i in xrange(y) for j in xrange(x)]
# for i,j in s:
# color = rint(img[i,j]/ROUND)*ROUND
# color = '#%02X%02X%02X' % tuple(color.tolist()[::-1])
# fmat = t.add_format({'bg_color':color})
# ts.write(i,j,'',fmat)
# if j==0:print i,'/',y
# t.close()
# py3
import cv2
from numpy import *
from xlsxwriter.workbook import Workbook
ROUND = 7.
img = cv2.imread('123.jpg')
y,x,ch = img.shape
img = cv2.resize(img,(int(y/3),int(x/3)))
y,x,ch = img.shape
t = Workbook('pic.xlsx')
ts = t.add_worksheet()
ts.set_default_row(height=1.8)
ts.set_column(0,5000,.2)
s = [(i,j) for i in range(y) for j in range(x)]
for i,j in s:
color = rint(img[i,j]/ROUND)*ROUND
color = '#%02X%02X%02X' % tuple(map(int,color.tolist()[::-1]))
fmat = t.add_format({'bg_color':color})
ts.write(i,j,'',fmat)
if j==0:print (i,'/',y)
t.close()