@@ -12,42 +12,62 @@ class EyeId(IntEnum):
12
12
13
13
class cal ():
14
14
def cal_osc (self , array ):
15
-
15
+ #print(self.calibration_frame_counter)
16
16
if self .calibration_frame_counter == 0 :
17
+
17
18
self .calibration_frame_counter = None
18
- lower_threshold = np .percentile (self .calibrate_config , 1 )
19
- upper_threshold = np .percentile (self .calibrate_config , 99 )
20
- self .calibrate_config = self .calibrate_config [(self .calibrate_config >= lower_threshold ) & (self .calibrate_config <= upper_threshold )]
19
+ values = np .array (self .val_list )
20
+
21
+ # Initialize the min_max_array with shape (2, num_outputs)
22
+ num_outputs = values .shape [1 ]
23
+ self .min_max_array = np .zeros ((2 , num_outputs ))
24
+
25
+ # Iterate over each output index
26
+ for i in range (num_outputs ):
27
+ # Calculate the lower and upper thresholds for the current index
28
+ lower_threshold = np .percentile (values [:, i ], 1 )
29
+ upper_threshold = np .percentile (values [:, i ], 99 )
30
+
31
+ # Filter out values within the thresholds for the current index
32
+ filtered_values = values [(values [:, i ] >= lower_threshold ) & (values [:, i ] <= upper_threshold ), i ]
33
+
34
+ # Extract the minimum and maximum values for the current index
35
+ min_value = np .min (filtered_values )
36
+ max_value = np .max (filtered_values )
21
37
22
- # Find maximum and minimum values in the array
23
- max_values = np .amax (self .calibrate_config , axis = 1 )
24
- min_values = np .amin (self .calibrate_config , axis = 1 )
25
- result = np .column_stack ((min_values , max_values ))
26
- result_flat = result .flatten ()
38
+ # Store the min and max values in the min_max_array
39
+ self .min_max_array [0 , i ] = min_value
40
+ self .min_max_array [1 , i ] = max_value
27
41
42
+ self .settings .calib_array = self .min_max_array
28
43
print ("[INFO] Calibration completed." )
29
- #print(self.calibrate_config)
30
- self .settings .calib_array = result_flat
44
+
31
45
PlaySound ('Audio/completed.wav' , SND_FILENAME | SND_ASYNC )
32
46
if self .calibration_frame_counter == 10 :
33
47
34
48
self .calibration_frame_counter -= 1
35
-
36
49
elif self .calibration_frame_counter != None :
37
50
51
+ self .val_list .append (array )
52
+
38
53
39
- self .calibrate_config = np .vstack ((self .calibrate_config , array .T ))
54
+ # self.calibrate_config = np.vstack((self.calibrate_config, array.T))
40
55
# np.append(self.calibrate_config, array.reshape(-1, 1), axis=1)
41
56
42
57
self .calibration_frame_counter -= 1
43
58
varcount = 0
44
59
filtered_output = []
45
- if self .settings .calib_array != None :
46
- for value in array :
47
- low_v = self .settings .calib_array [varcount ][0 ]
48
- high_v = self .settings .calib_array [varcount ][1 ]
49
- filterv = (value - low_v ) / (high_v - low_v )
50
- filtered_output .append (filterv )
51
- varcount += 1
52
- array = filtered_output
60
+ if self .settings .calib_array is not None and np .any (self .settings .calib_array ):
61
+ calibrated_array = np .zeros_like (array )
62
+ for i , value in enumerate (array ):
63
+ min_value = self .min_max_array [0 , i ]
64
+ max_value = self .min_max_array [1 , i ]
65
+
66
+ if min_value == max_value :
67
+ calibrated_value = 0.0 # Set to a default value (can be adjusted as needed)
68
+ else :
69
+ calibrated_value = (value - min_value ) / (max_value - min_value )
70
+
71
+ calibrated_array [i ] = calibrated_value
72
+ array = calibrated_array
53
73
return array
0 commit comments