Skip to content

Commit

Permalink
Refactor of EgocentricMapper init
Browse files Browse the repository at this point in the history
  • Loading branch information
soflc committed Oct 14, 2024
1 parent 5f8a470 commit 5952be2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"GPU 0: NVIDIA GeForce GTX 1080 Ti (UUID: GPU-72b7ddec-7074-1583-0076-9281c065ae9d)\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!nvidia-smi -L"
]
Expand All @@ -35,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -51,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -67,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -95,7 +87,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -117,7 +109,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -136,7 +128,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -162,46 +154,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Calculating optic flow: 100%|██████████| 1262/1262 [00:45<00:00, 27.85it/s]\n",
"Calculating optic flow: 100%|██████████| 1291/1291 [01:04<00:00, 20.09it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated offset of alternative egocentric video with respect to Neon scene video: 2.016 seconds (Pearson correlation: 0.9192123717590794)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Mapping gaze signal: 100%|██████████| 8155/8155 [01:44<00:00, 77.88it/s] "
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gaze mapped to alternative camera video saved at /users/sof/test_main/test_note/alternative_camera_gaze.csv\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"outputs": [],
"source": [
"import pupil_labs.egocentric_video_mapper.__main__ as main\n",
"from pathlib import Path\n",
Expand All @@ -221,9 +176,7 @@
"\n",
"args = Args()\n",
"\n",
"main.main(args)\n",
"\n",
"# Hi, so the Egocentric Video Mapper Alpha Lab is ready for internal testing, I created a Google Colab for use the tool"
"main.main(args)"
]
}
],
Expand Down
16 changes: 8 additions & 8 deletions src/pupil_labs/egocentric_video_mapper/gaze_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
class EgocentricMapper:
def __init__(
self,
neon_gaze_csv,
neon_video_path,
neon_timeseries_dir,
alternative_video_path,
neon_timestamps,
alternative_timestamps,
image_matcher,
image_matcher_parameters,
Expand All @@ -30,10 +28,8 @@ def __init__(
"""Class to map gaze from the Neon scene camera to an alternative camera. The gaze is mapped by calling the map_gaze method which uses correspondences between the two cameras to calculate the gaze transformation.
Args:
neon_gaze_csv (str): Path to the gaze.csv file from the Neon recording. The file should come from the Timeseries Data + Scene Video download from Pupil Cloud.
neon_video_path (str): Path to the video recorded by the Neon scene camera. The video comes from the Timeseries Data + Scene Video download from Pupil Cloud.
neon_timeseries_dir (str): Path to the directory containing the Neon scene video, the world_timestamps.csv file and the gaze.csv file.
alternative_video_path (str): Path to the video recorded by the alternative camera.
neon_timestamps (str): Path to the world_timestamps.csv from the Neon recording. The file should come from the Timeseries Data + Scene Video download from Pupil Cloud.
alternative_timestamps (str): Path to the alternative_camera_timestamps.csv from the alternative camera. This file is create by utils.write_timestamp_csv
image_matcher (str): Name of the image matcher to be used. For already implemented matcher check the feature_matcher module.
image_matcher_parameters (dict): Set of specific parameters for the image matcher. The parameters are passed as a dictionary with the parameter name as the key and the parameter value as the value.
Expand All @@ -44,10 +40,14 @@ def __init__(
alternative_fov (list, optional): Field of view in degrees of the Neon Scene camera (can be 2D or 1D). If 1D, it is assumed that the camera has the same field of view in both axes. If 2D, it is assumed that [fov_x, fov_y]. Defaults to [145, 76].
logging_level (str, optional): Level of logging to be used. Defaults to "ERROR".
"""
# Video file name in the Time Series + Video Scene
neon_video_path = next(Path(neon_timeseries_dir).rglob("*.mp4"))
self.neon_video = VideoHandler(neon_video_path)
self.alt_video = VideoHandler(alternative_video_path)

self.neon_vid_ts_nanosec = pd.read_csv(neon_timestamps)
self.neon_vid_ts_nanosec = pd.read_csv(
Path(neon_timeseries_dir, "world_timestamps.csv")
)
self.alt_vid_ts_nanosec = pd.read_csv(alternative_timestamps)
self.alt2neon_offset_sec = (
self.alt_vid_ts_nanosec["timestamp [ns]"].values[0]
Expand All @@ -59,7 +59,7 @@ def __init__(
self.alt_opticflow = pd.read_csv(alternative_opticflow_csv, dtype=np.float32)
self.alt_opticflow = self.alt_opticflow.iloc[1:]

self.neon_gaze = pd.read_csv(neon_gaze_csv) # @ 200Hz
self.neon_gaze = pd.read_csv(Path(neon_timeseries_dir, "gaze.csv")) # @ 200Hz
self.alt_gaze = self._create_alternative_gaze_df()

self.image_matcher = get_matcher(image_matcher, image_matcher_parameters)
Expand Down
10 changes: 3 additions & 7 deletions src/pupil_labs/egocentric_video_mapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ def generate_mapper_kwargs(
"disk_lightglue": {"num_features": 2048, "gpu_num": 0},
"dedode_lightglue": {"num_features": 5000, "gpu_num": 0},
}
# Video file name in the Time Series + Video Scene
neon_vid_path = next(Path(neon_timeseries_dir).rglob("*.mp4"))

alternative_timestamps_path = Path(output_dir, "alternative_camera_timestamps.csv")
if not alternative_timestamps_path.exists():
Expand All @@ -140,15 +138,13 @@ def generate_mapper_kwargs(
)

mapper_kwargs = {
"neon_gaze_csv": Path(neon_timeseries_dir, "gaze.csv"),
"neon_video_path": neon_vid_path,
"neon_timestamps": Path(neon_timeseries_dir, "world_timestamps.csv"),
"neon_opticflow_csv": Path(output_dir, f"neon_optic_flow.csv"),
"neon_timeseries_dir": Path(neon_timeseries_dir),
"alternative_video_path": alternative_vid_path,
"alternative_timestamps": alternative_timestamps_path,
"alternative_opticflow_csv": Path(output_dir, f"alternative_optic_flow.csv"),
"image_matcher": matcher_choice,
"image_matcher_parameters": image_matcher_parameters[matcher_choice],
"neon_opticflow_csv": Path(output_dir, f"neon_optic_flow.csv"),
"alternative_opticflow_csv": Path(output_dir, f"alternative_optic_flow.csv"),
"output_dir": Path(output_dir),
"patch_size": 1000,
"logging_level": logging_level,
Expand Down

0 comments on commit 5952be2

Please sign in to comment.