|
4 | 4 | import logging |
5 | 5 | import platform |
6 | 6 | from funscript_editor.utils.config import HYPERPARAMETER, SETTINGS |
| 7 | +from numpy.linalg import norm |
7 | 8 |
|
8 | 9 | def scale_signal(signal :list, lower: float = 0, upper: float = 99) -> list: |
9 | 10 | """ Scale an signal (list of float or int) between given lower and upper value |
@@ -137,6 +138,39 @@ def get_changepoints(score: list, fps: int, alpha: float) -> list: |
137 | 138 | return changepoints |
138 | 139 |
|
139 | 140 |
|
| 141 | +def get_edge_points(score: list, changepoints: dict, threshold: float = 150.0) -> list: |
| 142 | + """ Get Edge Points by calculate the distance to each point in the score. |
| 143 | +
|
| 144 | + Note: |
| 145 | + We map the time axis for between each predicted changepoint to 0 - 100 to |
| 146 | + get usable distances. |
| 147 | +
|
| 148 | + Args: |
| 149 | + score (list): the predicted score |
| 150 | + changepoints (dict): current min and max changepoints |
| 151 | + threshold (float): threshold value to predict additional edge point |
| 152 | +
|
| 153 | + Returns: |
| 154 | + list: list with index of the edge points (additional change points) |
| 155 | + """ |
| 156 | + edge_points = [] |
| 157 | + cp = changepoints['min']+changepoints['max'] |
| 158 | + cp.sort() |
| 159 | + if len(cp) < 2: return [] |
| 160 | + for i in range(len(cp)-1): |
| 161 | + start = np.array([0.0, score[cp[i]]]) |
| 162 | + end = np.array([100.0, score[cp[i]]]) |
| 163 | + distances = [ norm(np.cross(end-start, start-np.array([100.0 * (j - cp[i]) / (cp[i+1] - cp[i]), score[j]])))/norm(end-start) \ |
| 164 | + for j in range(cp[i], cp[i+1]) ] |
| 165 | + max_distance = max(distances) |
| 166 | + if max_distance > threshold: |
| 167 | + print("Add Edge point for distance", max_distance) |
| 168 | + edge_points.append(cp[i] + distances.index(max_distance)) |
| 169 | + |
| 170 | + return edge_points |
| 171 | + |
| 172 | + |
| 173 | + |
140 | 174 | def get_local_max_and_min_idx(score :list, fps: int, shift_min :int = 0, shift_max :int = 0) -> dict: |
141 | 175 | """ Get the local max and min positions in given signal |
142 | 176 |
|
|
0 commit comments