1
1
import numpy as np
2
+ from math import log
2
3
from enum import IntEnum
3
4
from utils .misc_utils import PlaySound , SND_FILENAME , SND_ASYNC
4
5
@@ -7,43 +8,65 @@ class CamId(IntEnum):
7
8
SETTINGS = 1
8
9
9
10
class cal ():
11
+
10
12
def cal_osc (self , array ):
11
13
#print(self.calibration_frame_counter)
12
14
if self .calibration_frame_counter == 0 :
15
+ if not self .config .use_n_calibration :
16
+ self .calibration_frame_counter = None
17
+ values = np .array (self .val_list )
13
18
14
- self .calibration_frame_counter = None
15
- values = np .array (self .val_list )
19
+ # Initialize the min_max_array with shape (2, num_outputs)
20
+ num_outputs = values .shape [1 ]
21
+ self .min_max_array = np .zeros ((2 , num_outputs ))
16
22
17
- # Initialize the min_max_array with shape (2, num_outputs)
18
- num_outputs = values .shape [1 ]
19
- self .min_max_array = np .zeros ((2 , num_outputs ))
23
+ # Iterate over each output index
24
+ for i in range (num_outputs ):
25
+ # Calculate the lower and upper thresholds for the current index
26
+ lower_threshold = np .percentile (values [:, i ], 1 )
27
+ upper_threshold = np .percentile (values [:, i ], 99 )
20
28
21
- # Iterate over each output index
22
- for i in range (num_outputs ):
23
- # Calculate the lower and upper thresholds for the current index
24
- lower_threshold = np .percentile (values [:, i ], 1 )
25
- upper_threshold = np .percentile (values [:, i ], 99 )
29
+ # Filter out values within the thresholds for the current index
30
+ filtered_values = values [(values [:, i ] >= lower_threshold ) & (values [:, i ] <= upper_threshold ), i ]
26
31
27
- # Filter out values within the thresholds for the current index
28
- filtered_values = values [(values [:, i ] >= lower_threshold ) & (values [:, i ] <= upper_threshold ), i ]
32
+ # Extract the minimum and maximum values for the current index
33
+ min_value = np .min (filtered_values )
34
+ max_value = np .max (filtered_values )
35
+
36
+ # Store the min and max values in the min_max_array
37
+ self .min_max_array [0 , i ] = min_value
38
+ self .min_max_array [1 , i ] = max_value
39
+ self .settings .calib_array = np .array2string (self .min_max_array , separator = ',' )
40
+ self .config_class .save ()
41
+ print ("[INFO] Calibration completed." )
42
+
43
+ PlaySound ('Audio/completed.wav' , SND_FILENAME | SND_ASYNC )
44
+
45
+ if self .config .use_n_calibration :
46
+ self .calibration_frame_counter = None
47
+ values = np .array (self .val_list )
48
+ deadzone_value = - 0.01 # Maybe adjust from app????
49
+ # Initialize the min_max_array with shape (2, num_outputs)
50
+ num_outputs = values .shape [1 ]
51
+ self .min_max_array = np .zeros ((2 , num_outputs ))
52
+ lower_threshold = np .clip ([np .mean (values , axis = 0 ) + deadzone_value ], 0 , 1 )
53
+ upper_threshold = np .ones ((1 , num_outputs )) # We don't need to adjust the max values.
54
+ print (lower_threshold )
55
+ print (upper_threshold )
56
+ self .min_max_array = np .array ([lower_threshold , upper_threshold ])
57
+ self .settings .calib_array = np .array2string (self .min_max_array , separator = ',' )
58
+ self .config_class .save ()
59
+ print ("[INFO] Calibration completed." )
29
60
30
- # Extract the minimum and maximum values for the current index
31
- min_value = np .min (filtered_values )
32
- max_value = np .max (filtered_values )
33
61
34
- # Store the min and max values in the min_max_array
35
- self .min_max_array [0 , i ] = min_value
36
- self .min_max_array [1 , i ] = max_value
37
- self .settings .calib_array = np .array2string (self .min_max_array , separator = ',' )
38
- self .config_class .save ()
39
- print ("[INFO] Calibration completed." )
40
62
41
- PlaySound ('Audio/completed.wav' , SND_FILENAME | SND_ASYNC )
42
63
43
- elif self .calibration_frame_counter != None :
44
64
65
+
66
+ elif self .calibration_frame_counter != None :
45
67
self .val_list .append (array )
46
68
self .calibration_frame_counter -= 1
69
+
47
70
48
71
if self .settings .calib_array is not None and self .config .use_calibration :
49
72
self .min_max_array = np .fromstring (self .settings .calib_array .replace ('[' , '' ).replace (']' , '' ), sep = ',' )
@@ -70,10 +93,10 @@ def cal_osc(self, array):
70
93
for i , value in enumerate (array ):
71
94
min_value = self .min_max_array [0 , i ]
72
95
73
-
74
96
calibrated_value = (value - min_value ) / (1.0 - min_value )
75
97
76
98
calibrated_array [i ] = calibrated_value
77
99
array = calibrated_array
78
-
100
+ print (array [4 ])
101
+ #array[4] = log((np.clip(array[4]*10,0,10))+1.0, 11) Log Filter: Move to filter system.
79
102
return np .clip (array ,0 ,1 ) # Clamp outputs between 0-1
0 commit comments