-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadcfg.py
106 lines (87 loc) · 2.63 KB
/
loadcfg.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Jun Zhang'
def loadcfg(bk_file):
f = open(bk_file, "r")
#skip txt for mean (r,g,b)
read_data=f.readline()
#read mean (r,g,b)
read_data=f.readline()
line=read_data.split(' ')
#print(line)
avg_r=int(line[0])
avg_g=int(line[1])
avg_b=int(line[2])
read_data=f.readline()
#read std_r, std_g, std_b
read_data=f.readline()
line=read_data.split(' ')
#print(line)
std_r=int(line[0])
std_g=int(line[1])
std_b=int(line[2])
f.close()
return (avg_r,avg_g,avg_b,std_r,std_g,std_b)
def savecfg(bk_file, avg_r, avg_g, avg_b, std_r, std_g, std_b, info, info2):
f = open(bk_file, "w")
f.write('%s\n' % info)
f.write('%s %s %s\n' % (avg_r, avg_g, avg_b))
f.write('%s\n' % info2)
f.write('%s %s %s\n' % (std_r, std_g, std_b))
f.close()
def loadalpha(alpha_file):
f = open(alpha_file, "r")
# skip txt for mean (r,g,b)
read_data = f.readline()
# read mean (r,g,b)
read_data = f.readline()
line = read_data.split(' ')
# print(line)
alpha = float(line[0])
f.close()
return alpha
def savecfg_cluster(bk_file, avg_r, avg_g, avg_b, std_r, std_g, std_b, info, info2):
cluster_to_save=len(avg_r)
f = open(bk_file, "w")
f.write('color_cluster_number \n')
f.write('%d\n' % cluster_to_save)
f.write('%s\n' % info)
for index in range(cluster_to_save):
f.write('%s %s %s\n' % (avg_r[index], avg_g[index], avg_b[index]))
f.write('%s\n' % info2)
for index in range(cluster_to_save):
f.write('%s %s %s\n' % (std_r[index], std_g[index], std_b[index]))
f.close()
def loadcfg_cluster(bk_file):
avg_r=[]
avg_g=[]
avg_b=[]
std_r=[]
std_g=[]
std_b=[]
f = open(bk_file, "r")
#skip txt for mean (r,g,b)
read_data=f.readline()
read_data = f.readline()
line=read_data.split('\n')
cluster_num=int(line[0])
read_data = f.readline()
for num in range(cluster_num):
#read mean (r,g,b)
read_data=f.readline()
line=read_data.split(' ')
#print(line)
avg_r.append(int(line[0]))
avg_g.append(int(line[1]))
avg_b.append(int(line[2]))
read_data=f.readline()
#read std_r, std_g, std_b
for num in range(cluster_num):
read_data=f.readline()
line=read_data.split(' ')
#print(line)
std_r.append(int(line[0]))
std_g.append(int(line[1]))
std_b.append(int(line[2]))
f.close()
return (avg_r,avg_g,avg_b,std_r,std_g,std_b)