Free Motion Capture for Everyone πβ¨
TypeScript
adding new post processing things
aaroncherian2c23768e43f6
diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/config.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/config.pynew file mode 100644index 00000000..504d0deb--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/config.py@@ -0,0 +1,34 @@+from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.constants import(+ TASK_INTERPOLATION,+ TASK_FILTERING,+ TASK_FINDING_GOOD_FRAME,+ TASK_SKELETON_ROTATION,+ PARAM_METHOD,+ PARAM_ORDER,+ PARAM_CUTOFF_FREQUENCY,+ PARAM_SAMPLING_RATE,+ PARAM_ROTATE_DATA,+ PARAM_AUTO_FIND_GOOD_FRAME,+ PARAM_GOOD_FRAME+)++default_settings = {+TASK_INTERPOLATION:+ {PARAM_METHOD: 'linear',+ PARAM_ORDER : 3+ },++ TASK_FILTERING:+ {'Method' : 'Butterworth Low Pass Filter',+ PARAM_ORDER: 4,+ PARAM_CUTOFF_FREQUENCY: 6,+ PARAM_SAMPLING_RATE:30+ },++ TASK_SKELETON_ROTATION:+ {PARAM_ROTATE_DATA: True,+ PARAM_AUTO_FIND_GOOD_FRAME: True,+ PARAM_GOOD_FRAME: None+ }+}+diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/constants.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/constants.pynew file mode 100644index 00000000..b7f9659c--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/constants.py@@ -0,0 +1,14 @@+TASK_INTERPOLATION = "interpolation"+TASK_FILTERING = "filtering"+TASK_FINDING_GOOD_FRAME = "finding good frame"+TASK_SKELETON_ROTATION = "skeleton rotation"+TASK_RESULTS_VISUALIZATION = "results visualization"+TASK_DATA_SAVED = "data saved"++PARAM_METHOD = "Method"+PARAM_ORDER = "Order"+PARAM_CUTOFF_FREQUENCY = "Cutoff Frequency"+PARAM_SAMPLING_RATE = "Sampling Rate"+PARAM_ROTATE_DATA = "Rotate Data"+PARAM_AUTO_FIND_GOOD_FRAME = "Auto-find Good Frame"+PARAM_GOOD_FRAME = "Good Frame"\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/led_widgets.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/led_widgets.pynew file mode 100644index 00000000..b8641265--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/led_widgets.py@@ -0,0 +1,100 @@+from PyQt6.QtCore import Qt, QPointF, QRect+from PyQt6.QtGui import QPainter, QColor, QBrush, QLinearGradient, QPen+from PyQt6.QtWidgets import QWidget, QHBoxLayout, QLabel+from freemocap_utils.postprocessing_widgets.stylesheet import label_stylesheet+++class LEDIndicator(QWidget):+ def __init__(self, parent=None):+ super().__init__(parent)+ self.setFixedSize(15, 15)+ self.color = QColor(156,0,0)++ def set_not_started_process_color(self):+ self.color = QColor(156,0,0)+ self.update()++ def set_in_process_color(self):+ self.color = QColor(255,230,0)+ self.update()++ def set_finished_process_color(self):+ self.color = QColor(0,108,154)+ self.update()++ def set_color(self, r,g,b):+ self.color = QColor(r,g,b)+ self.update()++ def paintEvent(self, event):+ painter = QPainter(self)+ painter.setRenderHint(QPainter.RenderHint.Antialiasing)++ diameter = min(self.width(), self.height())++ # Create a gradient for the LED color+ gradient = QLinearGradient(QPointF(0, 0), QPointF(diameter, diameter))+ gradient.setColorAt(0, self.color.lighter(150))+ gradient.setColorAt(1, self.color.darker(150))++ # Paint the LED circle with the gradient+ painter.setBrush(QBrush(gradient))+ painter.setPen(Qt.PenStyle.NoPen)+ painter.drawEllipse(QPointF(self.rect().center()), diameter / 2, diameter / 2)+++ # Add a subtle border to the LED circle+ border_color = self.color.lighter(150)+ border_rect = QRect(0, 0, diameter, diameter)+ painter.setBrush(Qt.BrushStyle.NoBrush)+ painter.setPen(QPen(border_color, 1))+ painter.drawEllipse(QPointF(self.rect().center()), diameter / 2, diameter / 2)++++class LedContainer(QWidget):+ def __init__(self, task_list):+ super().__init__()+ self.task_list = task_list+ self.layout = QHBoxLayout()++ def create_led_indicators(self):+ self.progress_led_dict = {}++ for task in self.task_list:+ #create an LED indicator for each task in the task list+ led_indicator = LEDIndicator()+ self.progress_led_dict[task] = led_indicator++ led_label = QLabel(task.capitalize())+ led_label.setStyleSheet(label_stylesheet)++ led_item_layout = QHBoxLayout()+ led_item_layout.addWidget(led_indicator)+ led_item_layout.addWidget(led_label)++ self.layout.addLayout(led_item_layout)++ self.layout.addStretch()++ return self.progress_led_dict, self.layout++ def change_leds_to_tasks_not_started_color(self):+ #reset all LEDs+ for led_indicator in self.progress_led_dict.values():+ led_indicator.set_not_started_process_color()+++ def change_led_to_task_not_started_color(self, task):+ #reset a single LED+ if task in self.progress_led_dict:+ self.progress_led_dict[task].set_not_started_process_color()++ def change_led_to_task_is_running_color(self,task):+ if task in self.progress_led_dict:+ self.progress_led_dict[task].set_in_process_color()++ def change_led_to_task_is_finished_color(self,task):+ if task in self.progress_led_dict:+ self.progress_led_dict[task].set_finished_process_color()+diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/filtering_menu.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/filtering_menu.pynew file mode 100644index 00000000..a7935415--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/filtering_menu.py@@ -0,0 +1,82 @@++import numpy as np++from PyQt6.QtWidgets import QWidget,QVBoxLayout, QPushButton, QGroupBox+++from freemocap_utils.postprocessing_widgets.task_worker_thread import TaskWorkerThread+from freemocap_utils.postprocessing_widgets.parameter_tree_builder import create_filter_parameter_tree, create_filter_page_settings_dict+from freemocap_utils.postprocessing_widgets.visualization_widgets.timeseries_view_widget import TimeSeriesPlotterWidget+from freemocap_utils.postprocessing_widgets.visualization_widgets.marker_selector_widget import MarkerSelectorWidget+from freemocap_utils.postprocessing_widgets.stylesheet import groupbox_stylesheet++from freemocap_utils.constants import (+ TASK_INTERPOLATION,+ TASK_FILTERING,+)++class FilteringMenu(QWidget):+ def __init__(self, freemocap_raw_data:np.ndarray):+ super().__init__()++ self.setStyleSheet(groupbox_stylesheet)++ layout = QVBoxLayout()+ self.freemocap_raw_data = freemocap_raw_data+ self.processed_freemocap_data = None++ # Timeseries and marker selector groupbox+ self.time_series_groupbox = self.create_time_series_groupbox()+ self.filter_param_tree_groupbox = self.create_filtering_groupbox()++ layout.addWidget(self.time_series_groupbox)+ layout.addWidget(self.filter_param_tree_groupbox)++ self.run_filter_button = QPushButton('Run Filter')+ self.run_filter_button.clicked.connect(self.run_filter_task)+ layout.addWidget(self.run_filter_button)++ self.update_timeseries_plot()++ self.setLayout(layout)+ self.connect_signals_to_slots()++ def create_time_series_groupbox(self):+ groupbox = QGroupBox("View time series for a selected marker")+ time_series_layout = QVBoxLayout()+ self.marker_selector_widget = MarkerSelectorWidget()+ time_series_layout.addWidget(self.marker_selector_widget)+ self.time_series_plotter_widget = TimeSeriesPlotterWidget()+ time_series_layout.addWidget(self.time_series_plotter_widget)+ groupbox.setLayout(time_series_layout)+ return groupbox++ def create_filtering_groupbox(self):+ groupbox = QGroupBox("Filtering Parameters")+ filter_params_layout = QVBoxLayout()+ self.filter_param_tree = create_filter_parameter_tree()+ filter_params_layout.addWidget(self.filter_param_tree)+ groupbox.setLayout(filter_params_layout)+ return groupbox++ def update_timeseries_plot(self, reset_axes = True):+ self.time_series_plotter_widget.update_plot(marker_to_plot=self.marker_selector_widget.current_marker, original_freemocap_data=self.freemocap_raw_data , processed_freemocap_data=self.processed_freemocap_data,reset_axes = reset_axes)++ def connect_signals_to_slots(self):+ self.marker_selector_widget.marker_to_plot_updated_signal.connect(lambda: self.update_timeseries_plot(reset_axes=True))++ def run_filter_task(self):+ self.settings_dict = create_filter_page_settings_dict()+ self.worker_thread = TaskWorkerThread(+ raw_skeleton_data=self.freemocap_raw_data,+ task_list= [TASK_INTERPOLATION,+ TASK_FILTERING],+ settings=self.settings_dict,+ all_tasks_finished_callback=self.handle_filter_result)+ self.worker_thread.start()+++ def handle_filter_result(self, task_results: dict):+ self.processed_freemocap_data = task_results[TASK_FILTERING]['result']+ self.update_timeseries_plot(reset_axes=False)+diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/interpolation_menu.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/interpolation_menu.pynew file mode 100644index 00000000..5e6958a2--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/interpolation_menu.py@@ -0,0 +1,78 @@++import numpy as np++from PyQt6.QtWidgets import QWidget,QVBoxLayout, QPushButton,QGroupBox++from freemocap_utils.postprocessing_widgets.task_worker_thread import TaskWorkerThread+from freemocap_utils.postprocessing_widgets.parameter_tree_builder import create_interpolation_parameter_tree, create_interpolation_page_settings_dict+from freemocap_utils.postprocessing_widgets.visualization_widgets.timeseries_view_widget import TimeSeriesPlotterWidget+from freemocap_utils.postprocessing_widgets.visualization_widgets.marker_selector_widget import MarkerSelectorWidget+from freemocap_utils.postprocessing_widgets.stylesheet import groupbox_stylesheet++from freemocap_utils.constants import (+ TASK_INTERPOLATION,+)+++class InterpolationMenu(QWidget):+ def __init__(self, freemocap_raw_data:np.ndarray):+ super().__init__()+ layout = QVBoxLayout()+++ self.setStyleSheet(groupbox_stylesheet)++ self.freemocap_raw_data = freemocap_raw_data+ self.processed_freemocap_data = None++ self.time_series_groupbox = self.create_time_series_groupbox()+ self.interpolation_param_tree_groupbox = self.create_interpolation_groupbox()++ layout.addWidget(self.time_series_groupbox)+ layout.addWidget(self.interpolation_param_tree_groupbox)++ self.run_interpolation_button = QPushButton('Run Interpolation')+ self.run_interpolation_button.clicked.connect(self.run_interpolation_task)+ layout.addWidget(self.run_interpolation_button)++ self.update_timeseries_plot()++ self.setLayout(layout)+ self.connect_signals_to_slots()++ def create_time_series_groupbox(self):+ groupbox = QGroupBox("View time series for a selected marker")+ time_series_layout = QVBoxLayout()+ self.marker_selector_widget = MarkerSelectorWidget()+ time_series_layout.addWidget(self.marker_selector_widget)+ self.time_series_plotter_widget = TimeSeriesPlotterWidget()+ time_series_layout.addWidget(self.time_series_plotter_widget)+ groupbox.setLayout(time_series_layout)+ return groupbox++ def create_interpolation_groupbox(self):+ groupbox = QGroupBox("Interpolation Parameters")+ interpolation_params_layout = QVBoxLayout()+ self.interpolation_param_tree = create_interpolation_parameter_tree()+ interpolation_params_layout.addWidget(self.interpolation_param_tree)+ groupbox.setLayout(interpolation_params_layout)+ return groupbox++ def update_timeseries_plot(self, reset_axes = True):+ self.time_series_plotter_widget.update_plot(marker_to_plot=self.marker_selector_widget.current_marker, original_freemocap_data=self.freemocap_raw_data , processed_freemocap_data=self.processed_freemocap_data,reset_axes = reset_axes)++ def connect_signals_to_slots(self):+ self.marker_selector_widget.marker_to_plot_updated_signal.connect(lambda: self.update_timeseries_plot(reset_axes=True))++ def run_interpolation_task(self):+ self.settings_dict = create_interpolation_page_settings_dict()+ self.worker_thread = TaskWorkerThread(+ raw_skeleton_data=self.freemocap_raw_data,+ task_list= [TASK_INTERPOLATION],+ settings=self.settings_dict,+ all_tasks_finished_callback=self.handle_interpolation_result)+ self.worker_thread.start()++ def handle_interpolation_result(self, task_results: dict):+ self.processed_freemocap_data = task_results[TASK_INTERPOLATION]['result']+ self.update_timeseries_plot(reset_axes=False)\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/main_menu.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/main_menu.pynew file mode 100644index 00000000..3fe50634--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/menus/main_menu.py@@ -0,0 +1,201 @@+++import numpy as np++from PyQt6.QtWidgets import QWidget,QVBoxLayout, QPushButton,QGroupBox, QHBoxLayout, QLineEdit, QLabel++from PyQt6.QtCore import pyqtSignal++from freemocap_utils.postprocessing_widgets.visualization_widgets.slider_widget import FrameCountSlider+from freemocap_utils.postprocessing_widgets.task_worker_thread import TaskWorkerThread+from freemocap_utils.postprocessing_widgets.visualization_widgets.skeleton_viewers_container import SkeletonViewersContainer+from freemocap_utils.postprocessing_widgets.led_widgets import LedContainer+from freemocap_utils.postprocessing_widgets.parameter_tree_builder import create_main_page_parameter_tree, create_main_page_settings_dict, rotation_params+from freemocap_utils.postprocessing_widgets.stylesheet import groupbox_stylesheet, button_stylesheet++from freemocap_utils.constants import (+ TASK_INTERPOLATION,+ TASK_FILTERING,+ TASK_FINDING_GOOD_FRAME,+ TASK_SKELETON_ROTATION,+ TASK_RESULTS_VISUALIZATION,+ TASK_DATA_SAVED,+ PARAM_AUTO_FIND_GOOD_FRAME,+ PARAM_ROTATE_DATA+)++class MainMenu(QWidget):++ save_skeleton_data_signal = pyqtSignal(object,object,object)+ def __init__(self,freemocap_raw_data:np.ndarray):+ super().__init__()++ self.led_names = [+ #list of the task names that are used to label the leds (and activate them based on task callbacks)+ TASK_INTERPOLATION,+ TASK_FILTERING,+ TASK_FINDING_GOOD_FRAME,+ TASK_SKELETON_ROTATION,+ TASK_RESULTS_VISUALIZATION,+ TASK_DATA_SAVED,+ ]++ self.task_list = [+ #a list of the tasks controlled by the main menu page+ TASK_INTERPOLATION,+ TASK_FILTERING,+ TASK_FINDING_GOOD_FRAME,+ TASK_SKELETON_ROTATION,+ ]+ layout = QVBoxLayout()++ self.setStyleSheet(groupbox_stylesheet)++ self.freemocap_raw_data = freemocap_raw_data++ skeleton_viewer_groupbox = self.create_skeleton_viewer_groupbox()+ layout.addWidget(skeleton_viewer_groupbox)++ parameter_groupbox = self.create_parameter_groupbox()+ layout.addWidget(parameter_groupbox)++ self.skeleton_viewers_container.plot_raw_skeleton(self.freemocap_raw_data)++ led_groupbox = self.create_led_groupbox()+ layout.addWidget(led_groupbox)++ save_groupbox = self.create_save_widgets()+ layout.addWidget(save_groupbox)++ self.connect_signals_to_slots()++ self.setLayout(layout)+++ def connect_signals_to_slots(self):+ self.frame_count_slider.slider.valueChanged.connect(lambda: self.update_viewer_plots(self.frame_count_slider.slider.value()))++ def create_led_groupbox(self):+ groupbox = QGroupBox('Processing Progress')+ self.led_container = LedContainer(self.led_names)+ self.progress_led_dict, led_layout = self.led_container.create_led_indicators()+ groupbox.setLayout(led_layout)+ return groupbox++ def create_skeleton_viewer_groupbox(self):+ groupbox = QGroupBox('View your raw and processed mocap data')+ viewer_layout = QVBoxLayout()+ self.frame_count_slider = FrameCountSlider(num_frames= self.freemocap_raw_data.shape[0])+ viewer_layout.addWidget(self.frame_count_slider)+ self.skeleton_viewers_container = SkeletonViewersContainer()+ viewer_layout.addWidget(self.skeleton_viewers_container)+ groupbox.setLayout(viewer_layout)+ return groupbox++ def create_parameter_groupbox(self):+ groupbox = QGroupBox('Processing Parameters')+ parameter_layout = QVBoxLayout()+ self.main_tree = create_main_page_parameter_tree()+ parameter_layout.addWidget(self.main_tree)+ groupbox.setLayout(parameter_layout)+ return groupbox++ def create_save_widgets(self):+ groupbox = QGroupBox('Process and save out data')+ process_and_save_layout = QVBoxLayout()++ self.process_button = QPushButton('Process data and view results')+ self.process_button.clicked.connect(self.postprocess_data)+ self.process_button.setStyleSheet(button_stylesheet)+ process_and_save_layout.addWidget(self.process_button)++ save_layout = QHBoxLayout()++ save_label = QLabel('Name for saved file:')+ save_layout.addWidget(save_label)+ self.save_entry = QLineEdit()+ self.save_entry.setMaximumWidth(600)+ self.save_entry.setText('mediapipe_postprocessed_3d_xyz')+ save_layout.addWidget(self.save_entry)++ self.save_button = QPushButton('Save out data')+ self.save_button.setMinimumSize(300, 20)+ self.save_button.setStyleSheet(button_stylesheet)+ self.save_button.clicked.connect(self.save_skeleton_data)+ save_layout.addWidget(self.save_button)+ save_layout.addStretch(0)++ process_and_save_layout.addLayout(save_layout)+ groupbox.setLayout(process_and_save_layout)+ return groupbox++ def update_viewer_plots(self, frame_to_plot):+ self.skeleton_viewers_container.update_raw_viewer_plot(frame_to_plot)+ self.skeleton_viewers_container.update_processed_viewer_plot(frame_to_plot)++ def postprocess_data(self):+ self.led_container.change_leds_to_tasks_not_started_color()+ self.settings_dict = create_main_page_settings_dict()+ self.worker_thread = TaskWorkerThread(+ raw_skeleton_data=self.freemocap_raw_data,+ task_list=self.task_list,+ settings=self.settings_dict,+ task_running_callback=self.handle_task_started,+ task_completed_callback=self.handle_task_completed,+ all_tasks_finished_callback=self.handle_plotting,+ )++ self.worker_thread.start()+++ def handle_task_started(self,task):+ self.led_container.change_led_to_task_is_running_color(task)++ def handle_task_completed(self,task,result=None):+ if result is None:+ self.led_container.change_led_to_task_not_started_color(task)+ else:+ self.led_container.change_led_to_task_is_finished_color(task)++ if task == TASK_FINDING_GOOD_FRAME:+ self.handle_good_frame_task_completed(result)++ def handle_good_frame_task_completed(self,result):+ good_frame_values_dict = self.settings_dict[TASK_SKELETON_ROTATION]++ if good_frame_values_dict[PARAM_ROTATE_DATA]: #if the 'rotate data' checkbox was checked+ #if auto find a good frame was selected, update the 'good frame' in the GUI with the frame that was found (and set frame finding to False)+ if good_frame_values_dict[PARAM_AUTO_FIND_GOOD_FRAME]:+ rotation_params.auto_find_good_frame_param.setValue(False)+ rotation_params.good_frame_param.setValue(str(result))++ def save_skeleton_data(self):+ final_skeleton = self.get_final_processed_skeleton()+ skeleton_save_file_name = self.save_entry.text()+ self.save_skeleton_data_signal.emit(final_skeleton,skeleton_save_file_name,self.settings_dict)+ self.handle_task_completed(TASK_DATA_SAVED, result = True)+++ def get_final_processed_skeleton(self):+ if self.rotated_skeleton is not None:+ return self.rotated_skeleton+ elif self.filtered_skeleton is not None:+ return self.filtered_skeleton+ else:+ return self.interpolated_skeleton++ def handle_plotting(self,task_results:dict):+ good_frame = task_results[TASK_FINDING_GOOD_FRAME]['result']+ self.interpolated_skeleton = task_results[TASK_INTERPOLATION]['result']+ self.filtered_skeleton = task_results[TASK_FILTERING]['result']+ self.rotated_skeleton = task_results[TASK_SKELETON_ROTATION]['result']++ if self.rotated_skeleton is not None:+ self.skeleton_viewers_container.plot_processed_skeleton(self.rotated_skeleton)+ else:+ self.skeleton_viewers_container.plot_processed_skeleton(self.filtered_skeleton)++ self.update_viewer_plots(good_frame)+ self.frame_count_slider.slider.setValue(good_frame)++ self.handle_task_completed(TASK_RESULTS_VISUALIZATION, result = True)diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/parameter_tree_builder.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/parameter_tree_builder.pynew file mode 100644index 00000000..9e87ff7c--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/parameter_tree_builder.py@@ -0,0 +1,74 @@++from pyqtgraph.parametertree import ParameterTree+from freemocap_utils.constants import TASK_INTERPOLATION, TASK_FILTERING, TASK_SKELETON_ROTATION, PARAM_ORDER+from freemocap_utils.postprocessing_widgets.parameter_widgets import interpolation_params, filter_params, rotation_params++#name mapping is used if the name of the key in the GUI parameter doesn't match what it needs to be in the settings dict+interpolation_name_mapping = {+ "Order (only used in spline interpolation)": PARAM_ORDER+}++def parameter_tree_to_dict(parameter_object, name_mapping=None):+ if name_mapping is None:+ name_mapping = {}++ for child in parameter_object.children():+ if child.hasChildren():+ child_dict = {}+ for grandchild in child.children():+ mapped_name = name_mapping.get(grandchild.name(), grandchild.name())+ child_dict[mapped_name] = grandchild.value()+ return child_dict+ else:+ return {child.name(): child.value()}++def create_main_page_parameter_tree():+ main_tree = ParameterTree()+ main_tree.addParameters(interpolation_params, showTop=False)+ main_tree.addParameters(filter_params, showTop=False)+ main_tree.addParameters(rotation_params,showTop = False)+ return main_tree++def create_main_page_settings_dict():+ interpolation_dict = parameter_tree_to_dict(interpolation_params, interpolation_name_mapping)+ filter_dict = parameter_tree_to_dict(filter_params)+ rotation_dict = parameter_tree_to_dict(rotation_params)++ settings_dict = {+ TASK_INTERPOLATION: interpolation_dict,+ TASK_FILTERING: filter_dict,+ TASK_SKELETON_ROTATION: rotation_dict+ }+ return settings_dict++def create_interpolation_parameter_tree():+ interpolation_tree = ParameterTree()+ interpolation_tree.addParameters(interpolation_params)++ return interpolation_tree++def create_interpolation_page_settings_dict():+ interpolation_dict = parameter_tree_to_dict(interpolation_params, interpolation_name_mapping)++ settings_dict = {+ TASK_INTERPOLATION: interpolation_dict,+ }+ return settings_dict++def create_filter_parameter_tree():+ filter_tree = ParameterTree()+ filter_tree.addParameters(filter_params)++ return filter_tree++def create_filter_page_settings_dict():+ interpolation_dict = parameter_tree_to_dict(interpolation_params, interpolation_name_mapping)+ filter_dict = parameter_tree_to_dict(filter_params)++ settings_dict = {+ TASK_INTERPOLATION: interpolation_dict,+ TASK_FILTERING: filter_dict,+ }+ return settings_dict++f = 2\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/parameter_widgets.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/parameter_widgets.pynew file mode 100644index 00000000..7fb99027--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/parameter_widgets.py@@ -0,0 +1,88 @@+from pyqtgraph.parametertree import Parameter,registerParameterType+from freemocap_utils.constants import(+ TASK_INTERPOLATION,+ TASK_FILTERING,+ TASK_FINDING_GOOD_FRAME,+ TASK_SKELETON_ROTATION,+ PARAM_METHOD,+ PARAM_ORDER,+ PARAM_CUTOFF_FREQUENCY,+ PARAM_SAMPLING_RATE,+ PARAM_ROTATE_DATA,+ PARAM_AUTO_FIND_GOOD_FRAME,+ PARAM_GOOD_FRAME+)+++interpolation_settings = [+ {"name": TASK_INTERPOLATION.title(), "type": "group", "children": [+ {"name": PARAM_METHOD, "type": "list", "values": ["linear", "cubic", "spline"]},+ {"name": "Order (only used in spline interpolation)", "type": "int", "value":3, "step":1}+ ]}+]++filter_settings = [+ {"name": TASK_FILTERING.title(), "type": "group", "children": [+ {"name": "Filter Type", "type": "list", "values": ["Butterworth Low Pass"]},+ {"name": PARAM_ORDER, "type":"int","value":4, "step":.1},+ {"name": PARAM_CUTOFF_FREQUENCY, "type": "float", "value": 6.0, "step": 0.1},+ {"name": PARAM_SAMPLING_RATE, "type": "float", "value": 30.0, "step": 0.1},+ ]}+]++rotation_settings = [+ {"name": TASK_SKELETON_ROTATION.title(), "type": "group", "children": [+ {"name": PARAM_ROTATE_DATA, "type": "bool", "value": True},+ {"name": "Instructions", "type": "str", "value": "Uncheck 'Auto-find Good Frame' to type in the good frame manually.", "readonly": True},+ {"name": PARAM_AUTO_FIND_GOOD_FRAME, "type": "bool", "value": True},+ {"name": PARAM_GOOD_FRAME, "type": "str", "value": "", "step": 1},+ ]}+]++class CustomRotationParam(Parameter):+ def __init__(self, *args, **kwargs):+ super().__init__(*args, **kwargs)+ self.rotate_data_param = self.child(TASK_SKELETON_ROTATION.title()).child(PARAM_ROTATE_DATA)+ self.auto_find_good_frame_param = self.child(TASK_SKELETON_ROTATION.title()).child(PARAM_AUTO_FIND_GOOD_FRAME)+ self.good_frame_param = self.child(TASK_SKELETON_ROTATION.title()).child(PARAM_GOOD_FRAME)++ self.rotate_data_param.sigValueChanged.connect(self.rotate_data_changed)+ self.auto_find_good_frame_param.sigValueChanged.connect(self.auto_find_good_frame_changed)++ def rotate_data_changed(self, value):+ enabled = value.value()+ self.auto_find_good_frame_param.setOpts(enabled=enabled)+ self.good_frame_param.setOpts(enabled=enabled)++ def auto_find_good_frame_changed(self, value):+ if value.value():+ self.good_frame_param.setValue("")+ self.good_frame_param.setOpts(readonly=True)+ else:+ if not self.good_frame_param.value():+ self.good_frame_param.setValue("0")+ self.good_frame_param.setOpts(readonly=False)+++interpolation_params = Parameter.create(name='interp_params', type='group', children=interpolation_settings)+filter_params = Parameter.create(name='filter_params',type='group', children=filter_settings )++registerParameterType('CustomRotationParam',CustomRotationParam)+rotation_params = Parameter.create(name='rotation_params', type='CustomRotationParam', children=rotation_settings) #the 'type' here refers to the parameter type we made the line above++++if __name__ == "__main__":++ def get_all_parameter_values(parameter_object):+ values = {}+ for child in parameter_object.children(): #using this just to access the second level of the parameter tree+ if child.hasChildren():+ for grandchild in child.children():+ values[grandchild.name()] = grandchild.value()+ else:+ values[child.name()] = child.value()+ return values++ values = get_all_parameter_values(filter_params)+ f =2\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/filter_data.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/filter_data.pynew file mode 100644index 00000000..024fd3e4--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/filter_data.py@@ -0,0 +1,26 @@+from scipy import signal+import numpy as np+from rich.progress import track++def butter_lowpass_filter(data, cutoff, sampling_rate, order):+ """ Run a low pass butterworth filter on a single column of data"""+ nyquist_freq = 0.5*sampling_rate+ normal_cutoff = cutoff / nyquist_freq+ # Get the filter coefficients+ b, a = signal.butter(order, normal_cutoff, btype='low', analog=False)+ y = signal.filtfilt(b, a, data)+ return y+++def filter_skeleton_data(skeleton_3d_data, order, cutoff, sampling_rate):+ """ Take in a 3d skeleton numpy array and run a low pass butterworth filter on each marker in the data"""+ num_frames = skeleton_3d_data.shape[0]+ num_markers = skeleton_3d_data.shape[1]+ filtered_data = np.empty((num_frames,num_markers,3))++ for marker in track(range(num_markers), description = 'Filtering Data'):+ for x in range(3):+ filtered_data[:,marker,x] = butter_lowpass_filter(skeleton_3d_data[:,marker,x],cutoff,sampling_rate,order)+++ return filtered_datadiff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/good_frame_finder.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/good_frame_finder.pynew file mode 100644index 00000000..27f6a3c5--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/good_frame_finder.py@@ -0,0 +1,84 @@+import numpy as np+++def find_velocity_values_within_limit(skeleton_velocity_data, velocity_limit):+ """+ This function takes in a skeleton velocity data array and a limit and returns the indices of the values that are within the limit+ """+ indices = []+ for i in range(len(skeleton_velocity_data)):+ if abs(skeleton_velocity_data[i]) <= velocity_limit:+ indices.append(i+1) #add 1 to account for the difference in indices between the position and velocity data+ return indices++def find_matching_indices_in_lists(list_1,list_2,list_3,list_4):+ """+ This function takes in four lists and returns the indices of the values that are in all four lists+ """+ matching_values = [x for x in list_1 if x in list_2 and x in list_3 and x in list_4]++ return matching_values+def find_best_velocity_guess(skeleton_velocity_data, skeleton_indices, velocity_guess, iteration_range):+ """+ This function iterates over velocity data and tries to pare down to a single frame that has the closest velocity to 0 for all foot markers+ """++ right_heel_index = skeleton_indices.index('right_heel')+ right_toe_index = skeleton_indices.index('right_foot_index')+ left_heel_index = skeleton_indices.index('left_heel')+ left_toe_index = skeleton_indices.index('left_foot_index')++ skeleton_data_velocity_x_right_heel = skeleton_velocity_data[:,right_heel_index,0]+ skeleton_data_velocity_x_right_toe = skeleton_velocity_data[:,right_toe_index,0]+ skeleton_data_velocity_x_left_heel = skeleton_velocity_data[:,left_heel_index,0]+ skeleton_data_velocity_x_left_toe = skeleton_velocity_data[:,left_toe_index,0]++ #get a list of the frames where the velocity for that marker is within the velocity limit+ right_heel_x_velocity_limits = find_velocity_values_within_limit(skeleton_data_velocity_x_right_heel, velocity_guess)+ right_toe_x_velocity_limits = find_velocity_values_within_limit(skeleton_data_velocity_x_right_toe, velocity_guess)+ left_heel_x_velocity_limits = find_velocity_values_within_limit(skeleton_data_velocity_x_left_heel, velocity_guess)+ left_toe_x_velocity_limits = find_velocity_values_within_limit(skeleton_data_velocity_x_left_toe, velocity_guess)++ #return a list of matching frame indices from the four lists generated above+ matching_values = find_matching_indices_in_lists(right_heel_x_velocity_limits, right_toe_x_velocity_limits, left_heel_x_velocity_limits, left_toe_x_velocity_limits)+ matching_values = [x for x in matching_values if x>75]++ #print(matching_values)+ if len(matching_values) > 1 and velocity_guess > 0:+ #if there are multiple matching values, decrease the guess a little bit and run the function again+ #+ velocity_guess = velocity_guess - iteration_range+ print('Current Velocity Guess:',velocity_guess, '| Number of Possible Frames:', len(matching_values), '| Possible Frames:', matching_values)+ matching_values, velocity_guess = find_best_velocity_guess(skeleton_velocity_data, skeleton_indices, velocity_guess, iteration_range)++ f = 2+ elif len(matching_values) == 0:+ #if there are no matching values (we decreased our guess too far), reset the guess to be a bit smaller and run the function again with smaller intervals between the guesses+ iteration_range = iteration_range/2+ matching_values, velocity_guess = find_best_velocity_guess(skeleton_velocity_data, skeleton_indices, velocity_guess + iteration_range*2, iteration_range)++ f = 2+ elif len(matching_values) == 1:+ print('Good Frame:', matching_values,'| Final Velocity Guess:',velocity_guess)++ return matching_values, velocity_guess+++def find_good_frame(skeleton_data, skeleton_indices:list, initial_velocity_guess:float, debug = False):+ """+ Finds a frame (called the good frame) where the velocity of both feet are closest to 0++ Input:+ skeleton data: a 3D numpy array of skeleton data in freemocap format+ skeleton indices: a list of joints being tracked by mediapipe/your 2d pose estimator+ initial velocity guess: just a starting guess for the optimizer. Can adjust if you're not getting the results you want+ debug: plots and displays the calculated good frame if True+ """++ skeleton_velocity_data = np.diff(skeleton_data, axis=0)++ matching_values, velocity_guess = find_best_velocity_guess(skeleton_velocity_data, skeleton_indices, initial_velocity_guess, iteration_range=.1)++ good_frame = matching_values[0]++ return good_frame\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/interpolate_data.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/interpolate_data.pynew file mode 100644index 00000000..fe86025e--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/interpolate_data.py@@ -0,0 +1,25 @@+import numpy as np+import pandas as pd+from rich.progress import track+++def interpolate_skeleton_data(skeleton_data:np.ndarray, method_to_use = 'linear', order = 3) -> np.ndarray:+ """ Takes in a 3d skeleton numpy array from freemocap and interpolates missing NaN values"""+ num_frames = skeleton_data.shape[0]+ num_markers = skeleton_data.shape[1]++ freemocap_interpolated_data = np.empty((num_frames, num_markers, 3))++ for marker in track(range(num_markers), description= 'Interpolating Data'):+ this_marker_skel3d_data = skeleton_data[:,marker,:]+ df = pd.DataFrame(this_marker_skel3d_data)+ df2 = df.interpolate(method = method_to_use,axis = 0, order = order) #use pandas interpolation methods to fill in missing data+ # df.interpolate(method=method_to_use, order = 5)+ this_marker_interpolated_skel3d_array = np.array(df2)+ #replace the remaining NaN values (the ones that often happen at the start of the recording)+ this_marker_interpolated_skel3d_array = np.where(np.isfinite(this_marker_interpolated_skel3d_array), this_marker_interpolated_skel3d_array, np.nanmean(this_marker_interpolated_skel3d_array))++ freemocap_interpolated_data[:,marker,:] = this_marker_interpolated_skel3d_array++ return freemocap_interpolated_data+\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/rotate_skeleton.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/rotate_skeleton.pynew file mode 100644index 00000000..a8a10923--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/postprocessing_functions/rotate_skeleton.py@@ -0,0 +1,174 @@++import numpy as np+from rich.progress import track++def create_vector(point1,point2):+ """Put two points in, make a vector"""+ vector = point2 - point1+ return vector++def calculate_unit_vector(vector):+ """Take in a vector, make it a unit vector"""+ unit_vector = vector/np.linalg.norm(vector)+ return unit_vector++def calculate_shoulder_center_XYZ_coordinates(single_frame_skeleton_data,left_shoulder_index,right_shoulder_index ):+ """Take in the left and right shoulder indices, and calculate the shoulder center point"""+ left_shoulder_point = single_frame_skeleton_data[left_shoulder_index,:]+ right_shoulder_point = single_frame_skeleton_data[right_shoulder_index,:]+ shoulder_center_XYZ_coordinates = (left_shoulder_point + right_shoulder_point)/2++ return shoulder_center_XYZ_coordinates+++def calculate_mid_hip_XYZ_coordinates(single_frame_skeleton_data,left_hip_index,right_hip_index):+ """Take in the left and right hip indices, and calculate the mid hip point"""+ left_hip_point = single_frame_skeleton_data[left_hip_index,:]+ right_hip_point = single_frame_skeleton_data[right_hip_index,:]+ mid_hip_XYZ_coordinates = (left_hip_point + right_hip_point)/2++ return mid_hip_XYZ_coordinates++def calculate_mid_foot_XYZ_coordinate(single_frame_skeleton_data,left_heel_index,right_heel_index,):+ """Take in the primary and secondary foot indices, and calculate the mid foot point"""+ right_foot_point = single_frame_skeleton_data[right_heel_index,:]+ left_foot_point = single_frame_skeleton_data[left_heel_index,:]+ mid_foot_XYZ_coordinates = (right_foot_point + left_foot_point)/2++ return mid_foot_XYZ_coordinates+++def translate_skeleton_frame(rotated_skeleton_data_frame, translation_distance):+ """Take in a frame of rotated skeleton data, and apply the translation distance to each point in the skeleton"""++ translated_skeleton_frame = rotated_skeleton_data_frame - translation_distance+ return translated_skeleton_frame++def translate_skeleton_to_origin(point_to_translate, original_skeleton_data):+ num_frames = original_skeleton_data.shape[0]++ translated_skeleton_data = np.zeros(original_skeleton_data.shape)++ for frame in track (range(num_frames), description = 'Translating Skeleton'):+ translated_skeleton_data[frame,:,:] = translate_skeleton_frame(original_skeleton_data[frame,:,:],point_to_translate)++ return translated_skeleton_data++def calculate_skewed_symmetric_cross_product(cross_product_vector):+ #needed in the calculate_rotation_matrix function+ skew_symmetric_cross_product = np.array([[0, -cross_product_vector[2], cross_product_vector[1]],+ [cross_product_vector[2], 0, -cross_product_vector[0]],+ [-cross_product_vector[1], cross_product_vector[0], 0]])+ return skew_symmetric_cross_product+++def calculate_rotation_matrix(vector1,vector2):+ """Put in two vectors to calculate the rotation matrix between those two vectors"""+ #based on the code found here: https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d"""++ identity_matrix = np.identity(3)+ vector_cross_product = np.cross(vector1,vector2)+ vector_dot_product = np.dot(vector1,vector2)+ skew_symmetric_cross_product = calculate_skewed_symmetric_cross_product(vector_cross_product)+ rotation_matrix = identity_matrix + skew_symmetric_cross_product + (np.dot(skew_symmetric_cross_product,skew_symmetric_cross_product))*(1 - vector_dot_product)/(np.linalg.norm(vector_cross_product)**2)++ return rotation_matrix++def rotate_point(point,rotation_matrix):+ rotated_point = np.dot(rotation_matrix,point)+ return rotated_point++def rotate_skeleton_frame(this_frame_aligned_skeleton_data, rotation_matrix):+ """Take in a frame of skeleton data, and apply the rotation matrix to each point in the skeleton"""++ this_frame_rotated_skeleton = np.zeros(this_frame_aligned_skeleton_data.shape) #initialize the array to hold the rotated skeleton data for this frame+ num_tracked_points = this_frame_aligned_skeleton_data.shape[0]++ for i in range(num_tracked_points):+ this_frame_rotated_skeleton[i,:] = rotate_point(this_frame_aligned_skeleton_data[i,:],rotation_matrix)++ return this_frame_rotated_skeleton++def rotate_skeleton_to_vector(reference_vector:np.ndarray, vector_to_rotate_to:np.ndarray, original_skeleton_np_array:np.ndarray) -> np.ndarray:+ """+ Find the rotation matrix needed to rotate the 'reference vector' to match the 'vector_to_rotate_to', and+ rotate the entire skeleton with that matrix.++ Input:+ Reference Vector: The vector on the skeleton that you want to rotate/base the rotation matrix on+ Vector_to_rotate_to: The vector that you want to align the skeleton too (i.e. the x-axis/y-axis etc.)+ Original skeleton data: The freemocap data you want to rotate+ Output:+ rotated_skeleton_data: A numpy data array of your rotated skeleton++ """++ num_frames = original_skeleton_np_array.shape[0]+ reference_unit_vector = calculate_unit_vector(reference_vector)+ rotation_matrix = calculate_rotation_matrix(reference_unit_vector, vector_to_rotate_to)++ rotated_skeleton_data_array = np.zeros(original_skeleton_np_array.shape)+ for frame in track(range(num_frames), description = 'Rotating Skeleton'):+ rotated_skeleton_data_array [frame,:,:] = rotate_skeleton_frame(original_skeleton_np_array[frame,:,:],rotation_matrix)++ return rotated_skeleton_data_array+++++++def align_skeleton_with_origin(skeleton_data:np.ndarray, skeleton_indices:list, good_frame:int) -> np.ndarray:++ """+ Takes in freemocap skeleton data and translates the skeleton to the origin, and then rotates the data+ so that the skeleton is facing the +y direction and standing in the +z direction++ Input:+ skeleton data: a 3D numpy array of skeleton data in freemocap format+ skeleton indices: a list of joints being tracked by mediapipe/your 2d pose estimator+ good frame: the frame that you want to base the rotation on (can be entered manually,+ or use the 'good_frame_finder.py' to calculate it)+ debug: If 'True', display a plot of the raw data and the 3 main alignment stages++ Output:+ spine aligned skeleton data: a 3d numpy array of the origin aligned data in freemocap format+ """+ left_shoulder_index = skeleton_indices.index('left_shoulder')+ right_shoulder_index = skeleton_indices.index('right_shoulder')++ left_hip_index = skeleton_indices.index('left_hip')+ right_hip_index = skeleton_indices.index('right_hip')++ left_heel_index = skeleton_indices.index('left_heel')+ right_heel_index = skeleton_indices.index('right_heel')++ origin = np.array([0, 0, 0])+ x_axis = np.array([1, 0, 0])+ y_axis = np.array([0, 1, 0])+ z_axis = np.array([0, 0, 1])++ x_vector = create_vector(origin,x_axis)+ y_vector = create_vector(origin,y_axis)+ z_vector = create_vector(origin,z_axis)+++ ## Translate the data such that the midpoint between the two feet is at the origin+ hip_translated_mid_foot_XYZ = calculate_mid_foot_XYZ_coordinate(skeleton_data[good_frame,:,:],left_heel_index, right_heel_index)+ foot_translated_skeleton_data = translate_skeleton_to_origin(hip_translated_mid_foot_XYZ,skeleton_data)++ # Rotate the skeleton to face the +y direction+ heel_vector_origin = foot_translated_skeleton_data[good_frame,right_heel_index,:]+ heel_vector = create_vector(heel_vector_origin ,foot_translated_skeleton_data[good_frame,left_heel_index,:])+++ y_aligned_skeleton_data = rotate_skeleton_to_vector(heel_vector,-1*x_vector,foot_translated_skeleton_data)++ #Rotating the skeleton so that the spine is aligned with +z+ y_aligned_mid_hip_XYZ = calculate_mid_hip_XYZ_coordinates(y_aligned_skeleton_data[good_frame,:,:],left_hip_index,right_hip_index)+ y_aligned_mid_shoulder_XYZ = calculate_shoulder_center_XYZ_coordinates(y_aligned_skeleton_data[good_frame,:,:], left_shoulder_index, right_shoulder_index)+ y_aligned_spine_vector = create_vector(y_aligned_mid_hip_XYZ,y_aligned_mid_shoulder_XYZ)++ spine_aligned_skeleton_data = rotate_skeleton_to_vector(y_aligned_spine_vector,z_vector,y_aligned_skeleton_data)++ return spine_aligned_skeleton_data, y_aligned_skeleton_data, foot_translated_skeleton_data\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/stylesheet.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/stylesheet.pynew file mode 100644index 00000000..0e0e4c01--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/stylesheet.py@@ -0,0 +1,32 @@+groupbox_stylesheet = """+QGroupBox {+ font-weight: bold;+ font-variant: small-caps;+ font-size: 17px;+ color: #006C9A;+}+++"""++button_stylesheet = """+QPushButton {+ font-weight: bold;+ font-variant: small-caps;+ font-size: 15px;+ color: #3A3A3A;++}++"""++label_stylesheet = """+QLabel {+ font-weight: bold;+ font-variant: small-caps;+ font-size: 15px;+ color: #3A3A3A;++}++"""\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/task_worker_thread.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/task_worker_thread.pynew file mode 100644index 00000000..881dd40b--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/task_worker_thread.py@@ -0,0 +1,111 @@++from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.postprocessing_widgets.postprocessing_functions.interpolate_data import interpolate_skeleton_data+from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.postprocessing_widgets.postprocessing_functions.filter_data import filter_skeleton_data+from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.postprocessing_widgets.postprocessing_functions.good_frame_finder import find_good_frame+from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.postprocessing_widgets.postprocessing_functions.rotate_skeleton import align_skeleton_with_origin++from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.postprocessing_widgets.visualization_widgets.mediapipe_skeleton_builder import mediapipe_indices++import numpy as np++import threading++from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.constants import (+ TASK_INTERPOLATION,+ TASK_FILTERING,+ TASK_FINDING_GOOD_FRAME,+ TASK_SKELETON_ROTATION,+ PARAM_METHOD,+ PARAM_ORDER,+ PARAM_CUTOFF_FREQUENCY,+ PARAM_SAMPLING_RATE,+ PARAM_ROTATE_DATA,+ PARAM_AUTO_FIND_GOOD_FRAME,+ PARAM_GOOD_FRAME+)++class TaskWorkerThread(threading.Thread):+ def __init__(self, raw_skeleton_data:np.ndarray, task_list:list, settings:dict, task_running_callback=None, task_completed_callback=None, all_tasks_finished_callback=None):+ super().__init__()++ self.raw_skeleton_data = raw_skeleton_data++ self.available_tasks = {+ #dictionary of all tasks that could be called in this thread, and their associated functions+ TASK_INTERPOLATION: self.interpolate_task,+ TASK_FILTERING: self.filter_task,+ TASK_FINDING_GOOD_FRAME: self.find_good_frame_task,+ TASK_SKELETON_ROTATION: self.rotate_skeleton_task,+ }++ #create a dictionary based of the tasks that were passed to the thread, and an empty results tab for each+ self.tasks = {task_name: {'function': self.available_tasks[task_name], 'result': None} for task_name in task_list}++ self.settings = settings++ self.task_running_callback = task_running_callback+ self.task_completed_callback = task_completed_callback+ self.all_tasks_finished_callback = all_tasks_finished_callback++++ def run(self):+ for task_info in self.tasks.values(): #clear any previous results+ task_info['result'] = None++ for task_name, task_info in self.tasks.items():++ if self.task_running_callback is not None:+ self.task_running_callback(task_name)++ #run the function for each task and return a bool of if it is completed, and a result object+ is_completed, result = task_info['function']()++ task_info['result'] = result++ #depending on if callback functions have been passed, return the result of the function, or None+ #if the task was not completed+ if is_completed:+ if self.task_completed_callback is not None:+ self.task_completed_callback(task_name, result)+ else:+ if self.task_completed_callback is not None:+ self.task_completed_callback(task_name, None)++ if self.all_tasks_finished_callback is not None:+ self.all_tasks_finished_callback(self.tasks)++ def interpolate_task(self):+ interpolation_values_dict = self.settings[TASK_INTERPOLATION]+ interpolated_skeleton = interpolate_skeleton_data(self.raw_skeleton_data, method_to_use=interpolation_values_dict[PARAM_METHOD], order=interpolation_values_dict[PARAM_ORDER])+ return True,interpolated_skeleton++ def filter_task(self):+ filter_values_dict = self.settings[TASK_FILTERING]+ filtered_skeleton = filter_skeleton_data(self.tasks[TASK_INTERPOLATION]['result'], order=filter_values_dict[PARAM_ORDER], cutoff=filter_values_dict[PARAM_CUTOFF_FREQUENCY], sampling_rate=filter_values_dict[PARAM_SAMPLING_RATE])+ return True,filtered_skeleton++ def find_good_frame_task(self):+ good_frame_values_dict = self.settings[TASK_SKELETON_ROTATION]++ if good_frame_values_dict[PARAM_ROTATE_DATA]:+ #if auto find is selected, find the good frame - if it is not, use the user entered value+ if good_frame_values_dict[PARAM_AUTO_FIND_GOOD_FRAME]:+ self.good_frame = find_good_frame(self.tasks[TASK_FILTERING]['result'], skeleton_indices=mediapipe_indices, initial_velocity_guess=.5)+ else:+ self.good_frame = int(good_frame_values_dict[PARAM_GOOD_FRAME])+ return True, self.good_frame+ else:+ #if no rotation is needed, we don't need to run the good frame finder+ self.good_frame = 0+ return False, self.good_frame++ def rotate_skeleton_task(self):+ rotate_values_dict = self.settings[TASK_SKELETON_ROTATION]+ if rotate_values_dict[PARAM_ROTATE_DATA]:+ origin_aligned_skeleton = align_skeleton_with_origin(self.tasks[TASK_FILTERING]['result'], mediapipe_indices, self.good_frame)[0]+ return True, origin_aligned_skeleton+ else:+ origin_aligned_skeleton = None+ return False, origin_aligned_skeleton+diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/marker_selector_widget.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/marker_selector_widget.pynew file mode 100644index 00000000..5ebc1247--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/marker_selector_widget.py@@ -0,0 +1,32 @@++from freemocap_utils.postprocessing_widgets.visualization_widgets.mediapipe_skeleton_builder import mediapipe_indices++from PyQt6.QtWidgets import QWidget, QVBoxLayout, QComboBox+from PyQt6.QtCore import pyqtSignal+++class MarkerSelectorWidget(QWidget):+ marker_to_plot_updated_signal = pyqtSignal()+ def __init__(self):+ super().__init__()++ self._layout = QVBoxLayout()+ self.setLayout(self._layout)++ combo_box_items = mediapipe_indices+ # combo_box_items.insert(0,'')+ self.marker_combo_box = QComboBox()+ self.marker_combo_box.addItems(combo_box_items)+ self.marker_combo_box.addItems(['center of mass'])+ self._layout.addWidget(self.marker_combo_box)++ self.current_marker = self.marker_combo_box.currentText()+ self.marker_combo_box.currentTextChanged.connect(self.return_marker)++ def return_marker(self):+ self.current_marker = self.marker_combo_box.currentText()+ self.marker_to_plot_updated_signal.emit()++ return self.current_marker++diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/mediapipe_skeleton_builder.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/mediapipe_skeleton_builder.pynew file mode 100644index 00000000..fb203b44--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/mediapipe_skeleton_builder.py@@ -0,0 +1,112 @@+from rich.progress import track+from pathlib import Path++mediapipe_indices = ['nose',+ 'left_eye_inner',+ 'left_eye',+ 'left_eye_outer',+ 'right_eye_inner',+ 'right_eye',+ 'right_eye_outer',+ 'left_ear',+ 'right_ear',+ 'mouth_left',+ 'mouth_right',+ 'left_shoulder',+ 'right_shoulder',+ 'left_elbow',+ 'right_elbow',+ 'left_wrist',+ 'right_wrist',+ 'left_pinky',+ 'right_pinky',+ 'left_index',+ 'right_index',+ 'left_thumb',+ 'right_thumb',+ 'left_hip',+ 'right_hip',+ 'left_knee',+ 'right_knee',+ 'left_ankle',+ 'right_ankle',+ 'left_heel',+ 'right_heel',+ 'left_foot_index',+ 'right_foot_index']++mediapipe_connections = {'shoulders':['left_shoulder','right_shoulder'],+ 'hips':['left_hip','right_hip'],+ 'torso_left': ['left_shoulder','left_hip'],+ 'torso_right':['right_shoulder','right_hip'],+ 'left_upper_arm':['left_shoulder','left_elbow'],+ 'left_lower_arm':['left_elbow','left_wrist'],+ 'left_upper_leg':['left_hip','left_knee'],+ 'left_lower_leg':['left_knee','left_ankle'],+ 'left_heel_connection':['left_ankle','left_heel'],+ 'left_foot':['left_heel','left_foot_index'],++ 'right_upper_arm':['right_shoulder','right_elbow'],+ 'right_lower_arm':['right_elbow','right_wrist'],+ 'right_upper_leg':['right_hip','right_knee'],+ 'right_lower_leg':['right_knee','right_ankle'],+ 'right_heel_connection':['right_ankle','right_heel'],+ 'right_foot':['right_heel','right_foot_index']}++reprojection_error_mediapipe_connections = {'left_upper_arm':['left_shoulder','left_elbow'],+ 'left_lower_arm':['left_elbow','left_wrist'],+ 'left_upper_leg':['left_hip','left_knee'],+ 'left_lower_leg':['left_knee','left_ankle'],+ 'left_foot':['left_ankle','left_heel','left_foot_index'],+ 'right_upper_arm':['right_shoulder','right_elbow'],+ 'right_lower_arm':['right_elbow','right_wrist'],+ 'right_upper_leg':['right_hip','right_knee'],+ 'right_lower_leg':['right_knee','right_ankle'],+ 'right_foot':['right_ankle','right_heel','right_foot_index']}+++def get_joint_coordinates_from_name(frame:int,joint_name:str,pose_estimation_markers,skel_3d_data):+ joint_index_number = pose_estimation_markers.index(joint_name)+ joint_coordinates = skel_3d_data[frame,joint_index_number,:]++ return joint_coordinates+++def build_skeleton(skel_3d_data,pose_estimation_markers,pose_estimation_connections):++ num_frames = skel_3d_data.shape[0]++ skeleton_connection_coordinates = []++ for frame in track(range(num_frames), 'Building Mediapipe Skeleton'):+ this_frame_connection_dict = {}+ for connection in pose_estimation_connections:++ joint_1_name = pose_estimation_connections[connection][0]+ joint_2_name = pose_estimation_connections[connection][1]++ joint_1_coordinates = get_joint_coordinates_from_name(frame,joint_1_name,pose_estimation_markers,skel_3d_data)+ joint_2_coordinates = get_joint_coordinates_from_name(frame,joint_2_name,pose_estimation_markers,skel_3d_data)++ this_connection_coordinates = [joint_1_coordinates,joint_2_coordinates]++ this_frame_connection_dict[connection] = this_connection_coordinates+ skeleton_connection_coordinates.append(this_frame_connection_dict)++ return skeleton_connection_coordinates+ f = 2++def get_mediapipe_indices(joint_center:str):+ return mediapipe_indices.index(joint_center)++++if __name__ == '__main__':+ freemocap_data_folder_path = Path(r'D:\freemocap2022\FreeMocap_Data')+ sessionID = 'sesh_2022-09-29_17_29_31'+ data_array_folder = 'DataArrays'+ array_name = 'mediaPipeSkel_3d.npy'+++ mediapipe_indices.index('left_heel')+ f = 2\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/skeleton_view_widget.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/skeleton_view_widget.pynew file mode 100644index 00000000..12d4fba8--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/skeleton_view_widget.py@@ -0,0 +1,115 @@+from PyQt6.QtCore import pyqtSignal+from PyQt6.QtWidgets import QWidget,QVBoxLayout++import matplotlib+matplotlib.use('QtAgg')+from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg+from matplotlib.figure import Figure++import numpy as np++from freemocap_utils.postprocessing_widgets.visualization_widgets.mediapipe_skeleton_builder import mediapipe_indices,mediapipe_connections,build_skeleton+++class SkeletonViewWidget(QWidget):++ session_folder_loaded_signal = pyqtSignal()++ def __init__(self, plot_title:str):+ super().__init__()++ self._layout = QVBoxLayout()+ self.setLayout(self._layout)++ self.plot_title = plot_title+ self.fig,self.ax = self.initialize_skeleton_plot()+ self._layout.addWidget(self.fig)++ self.skeleton_loaded = False++ self.current_xlim = None+ self.current_ylim = None+ self.current_zlim = None+++ def load_skeleton(self,skeleton_3d_data:np.ndarray):++ self.skeleton_3d_data = skeleton_3d_data+ self.mediapipe_skeleton = build_skeleton(self.skeleton_3d_data,mediapipe_indices,mediapipe_connections)+ self.reset_skeleton_3d_plot()++ self.skeleton_loaded = True+++ def initialize_skeleton_plot(self):+ fig = Mpl3DPlotCanvas(self, width=5, height=4, dpi=100)+ ax = fig.figure.axes[0]++ ax.set_title(self.plot_title)+ return fig, ax++ def reset_skeleton_3d_plot(self):+ self.ax.cla()+ self.calculate_axes_means(self.skeleton_3d_data)+ self.skel_x,self.skel_y,self.skel_z = self.get_x_y_z_data(0)+ self.plot_skel(0,self.skel_x,self.skel_y,self.skel_z)+++ def calculate_axes_means(self,skeleton_3d_data):+ self.mx_skel = np.nanmean(skeleton_3d_data[:,0:33,0])+ self.my_skel = np.nanmean(skeleton_3d_data[:,0:33,1])+ self.mz_skel = np.nanmean(skeleton_3d_data[:,0:33,2])+ self.skel_3d_range = 900++ def plot_skel(self,frame_number,skel_x,skel_y,skel_z):+ self.ax.scatter(skel_x,skel_y,skel_z)+ self.plot_skeleton_bones(frame_number)+ if self.current_xlim:+ self.ax.set_xlim([self.current_xlim[0],self.current_xlim[1]])+ self.ax.set_ylim([self.current_ylim[0],self.current_ylim[1]])+ self.ax.set_zlim([self.current_zlim[0],self.current_zlim[1]])+ else:+ self.ax.set_xlim([self.mx_skel-self.skel_3d_range, self.mx_skel+self.skel_3d_range])+ self.ax.set_ylim([self.my_skel-self.skel_3d_range, self.my_skel+self.skel_3d_range])+ self.ax.set_zlim([self.mz_skel-self.skel_3d_range, self.mz_skel+self.skel_3d_range])++ self.ax.set_title(self.plot_title)+ self.fig.figure.canvas.draw_idle()++ def plot_skeleton_bones(self,frame_number):+ this_frame_skeleton_data = self.mediapipe_skeleton[frame_number]+ for connection in this_frame_skeleton_data.keys():+ line_start_point = this_frame_skeleton_data[connection][0]+ line_end_point = this_frame_skeleton_data[connection][1]++ bone_x,bone_y,bone_z = [line_start_point[0],line_end_point[0]],[line_start_point[1],line_end_point[1]],[line_start_point[2],line_end_point[2]]++ self.ax.plot(bone_x,bone_y,bone_z)++ def get_x_y_z_data(self, frame_number:int):+ skel_x = self.skeleton_3d_data[frame_number,:,0]+ skel_y = self.skeleton_3d_data[frame_number,:,1]+ skel_z = self.skeleton_3d_data[frame_number,:,2]++ return skel_x,skel_y,skel_z++ def replot(self, frame_number:int):+ skel_x,skel_y,skel_z = self.get_x_y_z_data(frame_number)+ self.current_xlim = self.ax.get_xlim()+ self.current_ylim = self.ax.get_ylim()+ self.current_zlim = self.ax.get_zlim()+ self.ax.cla()+ self.plot_skel(frame_number,skel_x,skel_y,skel_z)+ #self.label.setText(str(frame_number))+++class Mpl3DPlotCanvas(FigureCanvasQTAgg):++ def __init__(self, parent=None, width=4, height=4, dpi=100):+ fig = Figure(figsize=(width, height), dpi=dpi)+ self.axes = fig.add_subplot(111,projection = '3d')+ super(Mpl3DPlotCanvas, self).__init__(fig)++++diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/skeleton_viewers_container.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/skeleton_viewers_container.pynew file mode 100644index 00000000..d80a7744--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/skeleton_viewers_container.py@@ -0,0 +1,30 @@+from PyQt6.QtWidgets import QWidget, QHBoxLayout+from freemocap_utils.postprocessing_widgets.visualization_widgets.skeleton_view_widget import SkeletonViewWidget+++class SkeletonViewersContainer(QWidget):+ def __init__(self):+ super().__init__()++ layout = QHBoxLayout()++ self.raw_skeleton_viewer = SkeletonViewWidget('Raw data')+ layout.addWidget(self.raw_skeleton_viewer)++ self.processed_skeleton_viewer = SkeletonViewWidget('Post-processed data')+ layout.addWidget(self.processed_skeleton_viewer)++ self.setLayout(layout)++ def plot_raw_skeleton(self, raw_skeleton_data):+ self.raw_skeleton_viewer.load_skeleton(raw_skeleton_data)++ def plot_processed_skeleton(self, processed_skeleton_data):+ self.processed_skeleton_viewer.load_skeleton(processed_skeleton_data)++ def update_raw_viewer_plot(self, frame_number):+ self.raw_skeleton_viewer.replot(frame_number)++ def update_processed_viewer_plot(self, frame_number):+ if self.processed_skeleton_viewer.skeleton_loaded:+ self.processed_skeleton_viewer.replot(frame_number)\ No newline at end of filediff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/slider_widget.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/slider_widget.pynew file mode 100644index 00000000..8554cb62--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/slider_widget.py@@ -0,0 +1,27 @@+from PyQt6.QtCore import Qt+from PyQt6.QtWidgets import QSlider, QWidget,QLabel,QHBoxLayout++class FrameCountSlider(QWidget):+ def __init__(self, num_frames:int):+ super().__init__()++ self._layout = QHBoxLayout()+ self.setLayout(self._layout)++ self.slider = QSlider(Qt.Orientation.Horizontal)+ self.slider.setMaximum(0)++ self.label = QLabel(str(self.slider.value()))+ self.slider.valueChanged.connect(lambda: self.label.setText(str(self.slider.value())))++ self._layout.addWidget(self.label)+ self._layout.addWidget(self.slider)++ self.set_slider_range(num_frames)+++ def set_slider_range(self,num_frames):+ self.slider_max = num_frames - 1+ self.slider.setValue(0)+ self.slider.setMaximum(self.slider_max)+diff --git a/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/timeseries_view_widget.py b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/timeseries_view_widget.pynew file mode 100644index 00000000..ddf95c00--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/freemocap_utils/postprocessing_widgets/visualization_widgets/timeseries_view_widget.py@@ -0,0 +1,89 @@++from PyQt6.QtWidgets import QWidget,QVBoxLayout++import matplotlib+matplotlib.use('QtAgg')++from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar+from matplotlib.figure import Figure++from freemocap_utils.postprocessing_widgets.visualization_widgets.mediapipe_skeleton_builder import mediapipe_indices++import numpy as np+++class TimeSeriesPlotCanvas(FigureCanvasQTAgg):++ def __init__(self, parent=None, width=15, height=4, dpi=100):+ fig = Figure(figsize=(width, height * 0.7), dpi=dpi)+ self.x_ax = fig.add_subplot(311)+ self.y_ax = fig.add_subplot(312)+ self.z_ax = fig.add_subplot(313)++ fig.subplots_adjust(hspace=0.4)+ fig.tight_layout(pad=2.5)++ super(TimeSeriesPlotCanvas, self).__init__(fig)++class TimeSeriesPlotterWidget(QWidget):++ def __init__(self):+ super().__init__()++ self._layout = QVBoxLayout()+ self.setLayout(self._layout)++ self.lines = []+++ self.fig, self.axes_list = self.initialize_skeleton_plot()++ toolbar = NavigationToolbar(self.fig, self)+ self._layout.addWidget(toolbar)+ self._layout.addWidget(self.fig)++ def initialize_skeleton_plot(self):+ fig = TimeSeriesPlotCanvas(self, width=12, height=9, dpi=100)+ self.x_ax = fig.figure.axes[0]+ self.y_ax = fig.figure.axes[1]+ self.z_ax = fig.figure.axes[2]++ self.axes_list = [self.x_ax,self.y_ax,self.z_ax]+ return fig, self.axes_list++ def get_mediapipe_indices(self,marker_to_plot):+ mediapipe_index = mediapipe_indices.index(marker_to_plot)+ return mediapipe_index+++ def update_plot(self,marker_to_plot:str, original_freemocap_data:np.ndarray, processed_freemocap_data:np.ndarray, reset_axes = True):+ axes_names = ['X Axis (mm)', 'Y Axis (mm)', 'Z Axis (mm)']++ mediapipe_index = self.get_mediapipe_indices(marker_to_plot)++ for line in self.lines:+ line.remove()+ self.lines = []++ for dimension, (ax, ax_name) in enumerate(zip(self.axes_list, axes_names)):+ if reset_axes:+ ax.cla()++ line1, = ax.plot(original_freemocap_data[:, mediapipe_index, dimension], label='Original Data', alpha=.8, color='red')+ self.lines.append(line1)+ if processed_freemocap_data is not None:+ line2, = ax.plot(processed_freemocap_data[:, mediapipe_index, dimension], label='Processed Data', alpha=.6, color='blue')+ self.lines.append(line2)++ ax.set_ylabel(ax_name)++ if dimension == 2: # put the xlabel only on the last plot+ ax.set_xlabel('Frame #')+ ax.legend()++ self.fig.figure.suptitle(f'{marker_to_plot} trajectory')++ self.fig.figure.canvas.draw_idle()+++diff --git a/freemocap/core_processes/post_process_skeleton_data/post_process_skeleton.py b/freemocap/core_processes/post_process_skeleton_data/post_process_skeleton.pynew file mode 100644index 00000000..f9eedb75--- /dev/null+++ b/freemocap/core_processes/post_process_skeleton_data/post_process_skeleton.py@@ -0,0 +1,89 @@++import numpy as np+from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.postprocessing_widgets.task_worker_thread \+ import TaskWorkerThread+from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.config import default_settings+from freemocap.core_processes.post_process_skeleton_data.freemocap_utils.constants import (+ TASK_INTERPOLATION,+ TASK_FILTERING,+ TASK_FINDING_GOOD_FRAME,+ TASK_SKELETON_ROTATION,+ PARAM_CUTOFF_FREQUENCY,+ PARAM_SAMPLING_RATE,+ PARAM_ORDER+)+++class PostProcessedDataHandler:+ def __init__(self):+ self.origin_aligned_skeleton_data = None+ self.filtered_skeleton_data = None++ def set_filtered_data(self, filtered_skeleton_data: np.ndarray):+++ self.filtered_skeleton_data = filtered_skeleton_data++ def set_origin_aligned_data(self, origin_aligned_skeleton_data: np.ndarray):+ self.origin_aligned_skeleton_data = origin_aligned_skeleton_data+++def handle_post_process_results(task_results: dict, data_handler: PostProcessedDataHandler):+ filtered_skeleton_data = task_results[TASK_FILTERING]['result']+ origin_aligned_skeleton_data = task_results[TASK_SKELETON_ROTATION]['result']++ data_handler.set_filtered_data(filtered_skeleton_data=filtered_skeleton_data)+ data_handler.set_origin_aligned_data(origin_aligned_skeleton_data=origin_aligned_skeleton_data)+++def get_settings_from_parameter_tree(recording_processing_parameter_model):+ rec = recording_processing_parameter_model++ filter_sampling_rate = rec.post_processing_parameters_model.framerate+ filter_cutoff_frequency = rec.post_processing_parameters_model.butterworth_filter_parameters.cutoff_frequency+ filter_order = rec.post_processing_parameters_model.butterworth_filter_parameters.order++ return filter_sampling_rate, filter_cutoff_frequency, filter_order+++def adjust_default_settings(filter_sampling_rate, filter_cutoff_frequency, filter_order):+ adjusted_settings = default_settings.copy()++ adjusted_settings[TASK_FILTERING][PARAM_CUTOFF_FREQUENCY] = filter_cutoff_frequency+ adjusted_settings[TASK_FILTERING][PARAM_SAMPLING_RATE] = filter_sampling_rate+ adjusted_settings[TASK_FILTERING][PARAM_ORDER] = filter_order++ return adjusted_settings+++def run_post_processing_worker(raw_skel3d_frame_marker_xyz: np.ndarray, settings_dictionary: dict):+ task_list = [TASK_INTERPOLATION, TASK_FILTERING, TASK_FINDING_GOOD_FRAME, TASK_SKELETON_ROTATION]+ post_processed_data_handler = PostProcessedDataHandler()+ worker_thread = TaskWorkerThread(raw_skeleton_data=raw_skel3d_frame_marker_xyz, task_list=task_list,+ settings=settings_dictionary,+ all_tasks_finished_callback=handle_post_process_results)+ worker_thread.start()++ return post_processed_data_handler+++def save_post_processed_data(processed_skel3d_frame_marker_xyz: np.ndarray,+ path_to_folder_where_we_will_save_this_data):+ Path(path_to_folder_where_we_will_save_this_data).mkdir(parents=True, exist_ok=True)+ np.save(+ str(path_to_folder_where_we_will_save_this_data / "mediaPipeSkel_3d_body_hands_face.npy"),+ processed_skel3d_frame_marker_xyz,+ )+++def post_process_data(recording_processing_parameter_model, raw_skel3d_frame_marker_xyz: np.ndarray,+ path_to_folder_where_we_will_save_this_data):+ filter_sampling_rate, filter_cutoff_frequency, filter_order = get_settings_from_parameter_tree(+ recording_processing_parameter_model)+ adjusted_settings = adjust_default_settings(filter_sampling_rate, filter_cutoff_frequency, filter_order)+ post_processed_data_handler = run_post_processing_worker(raw_skel3d_frame_marker_xyz=raw_skel3d_frame_marker_xyz,+ settings_dictionary=adjusted_settings)+ processed_skeleton_data = post_processed_data_handler.origin_aligned_skeleton_data+ save_post_processed_data(processed_skel3d_frame_marker_xyz=processed_skeleton_data,+ path_to_folder_where_we_will_save_this_data=path_to_folder_where_we_will_save_this_data)+#