-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalize.py
executable file
·51 lines (45 loc) · 1.42 KB
/
analize.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
import numpy as np
import time
from config import conf
import os
import cv2
ANGLE = 0
CLASS = 1
OCTAVE = 2
PTX = 3
PTY = 4
RESPONSE = 5
SIZE = 6
timestamp = time.strftime(conf.time_format_day, time.gmtime())
def get_stats_for_day():
statistics = {}
for data_file in os.listdir(conf.data_folder):
data_stamp = data_file[:-4]
filename = conf.data_folder + data_file
image = cv2.imread(conf.image_folder + data_stamp + '.jpg')
if data_file.startswith(timestamp):
data = np.load(filename)
stats = {}
#stats
stats['mean_size'] = np.mean(data[:,SIZE])
stats['max_size'] = np.max(data[:,SIZE])
stats['min_size'] = np.min(data[:,SIZE])
stats['area'] = np.sum(data[:,SIZE])
stats['area_percentage'] = stats['area']/image.size * 100
stats['n_blobs'] = float(len(data[:,SIZE]))
statistics[data_stamp] = stats
return statistics
def format_stats(stats):
report = ""
keys = [stat for stat in stats]
keys.sort()
for stat in keys:
report += "{}\n{}\n{}\n".format(("-"*len(stat)), stat, ("-"*len(stat)))
for feature in stats[stat]:
report+= "{}:{:.2}\n".format(feature, stats[stat][feature])
return report
stats = get_stats_for_day()
report = format_stats(stats)
f = open(conf.reports_folder + timestamp + '.txt', 'w')
f.write(report.rstrip())
f.close()