-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #433 from mprib/430-create-autorig_configjson-from…
…-calibration-footage 430 create autorig configjson from calibration footage
- Loading branch information
Showing
16 changed files
with
972 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
import pyxy3d.logger | ||
import json | ||
|
||
logger = pyxy3d.logger.get(__name__) | ||
from pyxy3d import __root__ | ||
import pytest | ||
import shutil | ||
import cv2 | ||
from pathlib import Path | ||
import time | ||
import pandas as pd | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from pyxy3d.trackers.tracker_enum import TrackerEnum | ||
|
||
def calculate_distance(xyz_trajectory_data:pd.DataFrame, point1:str, point2:str): | ||
""" | ||
Given a set of xyz trajectories from tracked and triangulated landmarks, calculate the | ||
mean distance between two named points, excluding outlier points for data cleanliness | ||
""" | ||
# calculate the distance | ||
distances = np.sqrt((xyz_trajectory_data[point1 + '_x'] - xyz_trajectory_data[point2 + '_x']) ** 2 + | ||
(xyz_trajectory_data[point1 + '_y'] - xyz_trajectory_data[point2 + '_y']) ** 2 + | ||
(xyz_trajectory_data[point1 + '_z'] - xyz_trajectory_data[point2 + '_z']) ** 2) | ||
|
||
|
||
# calculate Q1, Q3 and IQR for outlier detection | ||
Q1 = distances.quantile(0.25) | ||
Q3 = distances.quantile(0.75) | ||
IQR = Q3 - Q1 | ||
|
||
# filter out the outliers | ||
filtered_distances = distances[(distances >= Q1 - 1.5 * IQR) & (distances <= Q3 + 1.5 * IQR)] | ||
|
||
# calculate the average length | ||
average_length = filtered_distances.mean() | ||
return average_length | ||
|
||
|
||
def generate_metarig_config(tracker_enum: TrackerEnum, xyz_csv_path:Path): | ||
""" | ||
Stores metarig config json file within the tracker sub-directory within a recording folder | ||
""" | ||
tracker = tracker_enum.value() | ||
|
||
xyz_trajectories = pd.read_csv(xyz_csv_path) | ||
json_path = Path(xyz_csv_path.parent, f"metarig_config_{tracker.name}.json") | ||
|
||
# for testing purposes, need to make sure that this file is not there before proceeding | ||
json_path.unlink(missing_ok=True) | ||
assert not json_path.exists() | ||
|
||
autorig_config = {} # Dictionary that will become json | ||
|
||
# average distances across the bilateral measures | ||
for measure, points in tracker.metarig_bilateral_measures.items(): | ||
logger.info(f"Calculating mean distance (IQR) for {measure}") | ||
|
||
mean_distance = 0 | ||
for side in ["left", "right"]: | ||
|
||
point1 = f"{side}_{points[0]}" | ||
point2 = f"{side}_{points[1]}" | ||
|
||
distance = calculate_distance(xyz_trajectories, point1,point2) | ||
logger.info(f"Between {point1} and {point2} the mean distance is {distance}") | ||
mean_distance += distance/2 | ||
autorig_config[measure] = round(mean_distance,4) | ||
|
||
# calculate distance across symmetrical measures | ||
for measure, points in tracker.metarig_symmetrical_measures.items(): | ||
distance = calculate_distance(xyz_trajectories, points[0],points[1]) | ||
autorig_config[measure] = round(distance,4) | ||
|
||
# save output to file that will be in same folder as the associated xy_csv data | ||
with open(json_path,"w") as f: | ||
json.dump(autorig_config, f, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.