-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphical_analysis.py
77 lines (65 loc) · 2.14 KB
/
graphical_analysis.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
__author__ = "Adnan Karol"
__version__ = "1.0.0"
__maintainer__ = "Adnan Karol"
__email__ = "[email protected]"
__status__ = "DEV"
# Import Dependencies
import os
import matplotlib.pyplot as plt
def create_graphs_directory():
"""
Create a directory for saving graphs if it doesn't already exist.
"""
if not os.path.exists("Graphs"):
print("Creating 'Graphs' directory...")
os.makedirs("Graphs")
else:
print("'Graphs' directory already exists.")
def plot_ear_graph(EAR):
"""
Plot and save the Eye Aspect Ratio (EAR) graph for analysis.
Args:
EAR (list): List of EAR values to plot.
Returns:
int: Returns 1 if the plot is saved successfully, otherwise -1.
"""
try:
frames = list(range(1, len(EAR) + 1))
plt.figure()
plt.plot(frames, EAR, label='EAR', color='blue')
plt.xlabel('Frame')
plt.ylabel('Average EAR')
plt.title('Eye Aspect Ratio (EAR) Analysis')
plt.legend()
create_graphs_directory()
plt.savefig('Graphs/EAR.png', dpi=300, bbox_inches='tight')
plt.close() # Close the figure to free up memory
print("EAR plot saved successfully.")
return 1
except Exception as e:
print(f"Error saving EAR plot: {e}")
return -1
def plot_mar_graph(MAR):
"""
Plot and save the Mouth Aspect Ratio (MAR) graph for analysis.
Args:
MAR (list): List of MAR values to plot.
Returns:
int: Returns 1 if the plot is saved successfully, otherwise -1.
"""
try:
frames = list(range(1, len(MAR) + 1))
plt.figure()
plt.plot(frames, MAR, label='MAR', color='red')
plt.xlabel('Frame')
plt.ylabel('Average MAR')
plt.title('Mouth Aspect Ratio (MAR) Analysis')
plt.legend()
create_graphs_directory()
plt.savefig('Graphs/MAR.png', dpi=300, bbox_inches='tight')
plt.close() # Close the figure to free up memory
print("MAR plot saved successfully.")
return 1
except Exception as e:
print(f"Error saving MAR plot: {e}")
return -1