-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.py
61 lines (46 loc) · 1.55 KB
/
main2.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
54
55
56
57
58
59
60
61
# will work always, but maybe excel wont open, so scale down imagepip install opencv-python
# from openpyxl import Workbook
import openpyxl
# from openpyxl.styles import PatternFill
import fnct as hl
import cv2
import numpy as np
def nothing(x):
pass
path = "img.jpg"
# path = str(input())
img = cv2.imread(path)
# cv2.namedWindow("Display", cv2.WINDOW_AUTOSIZE)
# cv2.createTrackbar('R','Display',0,255,nothing)
# import openpyxl
wb = openpyxl.Workbook()
# sheet = wb["Sheet"] # This sheet is created by default
sheet = wb.active # This sheet is created by default
cnt = 0
srow, scol = img.shape[:2] # 1,048,576 rows or 16,384 columns, řádky, sloupce
# row vodorovně col vertikálně
# nastavení barev
for row in range(srow):
print("COLORED", row)
cnt = 0
row = row + 1
for col in range(scol):
col = col + 1
cnt = cnt + 1
# print(col, cnt)
letcol = hl.nl(cnt)
color = hl.rgb(img[row - 1][col - 1][2], img[row - 1][col - 1][1], img[row - 1][col - 1][0]) #formát RGB, beru z multdim arraye, indexy pozpátku kvůli OpenCV BGR
fill = openpyxl.styles.PatternFill("solid", start_color=color)
sheet["{}{}".format(letcol, row)].fill = fill # letter, řádek
# nastavení šířky na 1
for row in range(srow):
print("RESIZED ROWS", row)
row = row + 1
sheet.row_dimensions[row].height = 3.75
for col in range(scol):
print("RESIZED COL", col)
col = col + 1
coll = hl.nl(col)
sheet.column_dimensions[coll].width = 0.7
wb.save("wb3.xlsx")
print("complete")