Skip to content

Commit fa622a2

Browse files
committed
Threshold can be a parameter of the PostProcessing.
1 parent f820c3d commit fa622a2

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

PostProcessing/PostProcessVideos.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from video import extract_video_info
1515

1616

17-
THRESHOLD_NS = 10 * 1000 * 1000 # millis * micros * nanos
17+
DEFAULT_THRESHOLD_MILLIS = 10
18+
DEFAULT_THRESHOLD_NANOS = DEFAULT_THRESHOLD_MILLIS * 1000 * 1000 # millis * micros * nanos
1819

1920

2021
def scan_session_dir(input_dir: Path) -> Tuple[List[str], List[pd.DataFrame], List[str]]:
@@ -66,14 +67,13 @@ def scan_session_dir(input_dir: Path) -> Tuple[List[str], List[pd.DataFrame], Li
6667
#
6768
#
6869
#
69-
def main(input_dir: Path, output_dir: Path):
70+
def main(input_dir: Path, output_dir: Path, threshold_ns: int):
7071

7172
print(f"Scanning dir {str(input_dir)}...")
7273
clientIDs, df_list, mp4_list = scan_session_dir(input_dir)
7374

7475
n_clients = len(clientIDs)
7576

76-
7777
#
7878
# Print collected info
7979
for i in range(n_clients):
@@ -97,18 +97,21 @@ def main(input_dir: Path, output_dir: Path):
9797
# Find time ranges
9898
min_common, max_common = compute_time_range(repaired_df_list)
9999
# Trim the data frames to the time range
100-
trimmed_dataframes = trim_repaired_into_interval(repaired_df_list, min_common, max_common, THRESHOLD_NS)
100+
trimmed_dataframes = trim_repaired_into_interval(repaired_df_list, min_common, max_common, threshold_ns)
101101

102102
assert len(clientIDs) == len(trimmed_dataframes), f"Expected {len(clientIDs)} trimmed dataframes. Found f{len(trimmed_dataframes)}"
103103

104104
# Check that all the resulting dataframes have the same number of rows
105+
print("Checking if all clients we have the same number of frames in the repaired amd trimmed tables...")
105106
client0ID = clientIDs[0]
106107
client0size = len(trimmed_dataframes[0])
107-
print(f"For client {client0ID}: {client0size} frames")
108+
print(f"Client {client0ID} has {client0size} frames.")
108109
for cID, df in zip(clientIDs[1:], trimmed_dataframes[1:]):
109110
dfsize = len(df)
110111
if client0size != dfsize:
111-
raise Exception(f"For client {cID}: expecting {client0size} frames, found {dfsize}")
112+
raise Exception(f"For client {cID}: expecting {client0size} frames. Found {dfsize}."
113+
f" This might be due to an excessive phase offset during recording."
114+
f" Try to increase the threshold.")
112115

113116
print("Good. All trimmed dataframes have the same number of entries.")
114117

@@ -152,16 +155,25 @@ def main(input_dir: Path, output_dir: Path):
152155
"--outfolder", "-o", type=str, help="The folder where the repaired and aligned frames will be stored.",
153156
required=True
154157
)
158+
parser.add_argument(
159+
"--threshold", "-t", type=int, help="The allowed difference in ms between corresponding frames on different videos."
160+
" Increase this is post processing fails with trimmed tables of different sizes."
161+
f" Default is now {DEFAULT_THRESHOLD_MILLIS} ms.",
162+
required=False,
163+
default=DEFAULT_THRESHOLD_MILLIS
164+
)
155165

156166
args = parser.parse_args()
157167

158168
infolder = Path(args.infolder)
159169
outfolder = Path(args.outfolder)
170+
threshold_millis = args.threshold
171+
threshold_nanos = threshold_millis * 1000 * 1000
160172

161173
if not infolder.exists():
162174
raise Exception(f"Input folder '{infolder}' doesn't exist.")
163175

164176
if not outfolder.exists():
165177
raise Exception(f"Output folder '{outfolder}' doesn't exist.")
166178

167-
main(infolder, outfolder)
179+
main(infolder, outfolder, threshold_nanos)

PostProcessing/dataframes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,6 @@ def trim_repaired_into_interval(dfs, min_common, max_common, threshold) -> List[
120120
trimmed_df = df[selection_mask]
121121
trimmed_dataframes.append(trimmed_df)
122122

123+
assert len(trimmed_dataframes) <= len(df)
124+
123125
return trimmed_dataframes

PostProcessing/test_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from video import video_info
1515

16-
from PostProcessVideos import THRESHOLD_NS
16+
from PostProcessVideos import DEFAULT_THRESHOLD_NANOS
1717

1818

1919
RECSYNCH_SESSION_DIR_VAR = "RECSYNCH_SESSION_DIR"
@@ -94,7 +94,7 @@ def test_df_reparation(client_data):
9494

9595
tstamps = repaired_df["timestamp"]
9696
diffs = tstamps.diff().dropna()
97-
assert (diffs <= (time_step + THRESHOLD_NS)).all(), "some timestamps difference is longer than expected"
97+
assert (diffs <= (time_step + DEFAULT_THRESHOLD_NANOS)).all(), "some timestamps difference is longer than expected"
9898

9999

100100
def test_df_trimming(session_data):

0 commit comments

Comments
 (0)