-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_handler.py
81 lines (65 loc) · 2.18 KB
/
output_handler.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
'''****************************************************************************************************
output.py
handles the output of data to (in this case) a csv file
****************************************************************************************************'''
import csv # csv library
import cv2 as cv
import os
import errno
# Write data matrix to csv file f
def write_to_csv(f, data):
print("Writing data to csv file")
print("...")
writer = csv.writer(f)
writer.writerows(data)
print("Done!")
'''
Write Data:
-------------------------
writes relevant data into csv file
'''
def WriteData(m_csvFile, imgName, offBodyDistances):
'''
m_csvFile : m_csvFile to write to
imgName, String: name of image
offBodyDistances, list<double>: distances from center centroid
'''
# create writer object
csvWriter = csv.writer(m_csvFile)
# write a test line
csvWriter.writerow([imgName])
csvWriter.writerow(["count"] + [len(offBodyDistances)])
# write rows for each migrating point
for i in range (len(offBodyDistances)):
# for each offBodyDistance[i], get the name and writerow with name and distance
name = "m" + str(i+1)
csvWriter.writerow([name] + [offBodyDistances[i]])
csvWriter.writerow('')
csvWriter.writerow('')
# start new entry with a new line
'''
Manage/Create Output Folder:
-------------------------
Creates the output folder if it doesn't exist. If it exists already don't do anything
'''
def prep_output_environment(start_time):
try:
os.mkdir('./output/')
except OSError as e:
if e.errno == errno.EEXIST:
print("OutputHandler: output folder already created. Doing nothing...")
else:
raise # raise exception if it is not the not exist error
try:
os.mkdir('./output/output-{}/'.format(start_time))
except OSError as e:
print("Something weird is happening. Find me...")
'''
Save Image to output folder:
-------------------------
save image into an output folder to view later
'''
def save_image(image_to_save, file_name, output_path):
print ("Writing {} to {}".format(file_name, output_path))
cv.imwrite((output_path + file_name), image_to_save)
print ("Done\n")