-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CI
committed
Feb 4, 2024
0 parents
commit 461f260
Showing
247 changed files
with
44,257 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
144 changes: 144 additions & 0 deletions
144
_downloads/0b576ad9020dc38b1ea8157e97debdda/5_map_gaze.ipynb
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,144 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n# Run gaze mapping\n\nThis example shows how to run gaze mapping with a connected Pupil Core\nheadset.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>This example requires the dependencies for\n `streaming<streaming_dependencies>` and\n `pupil detection<pupil_detection_dependencies>`.</p></div>\n\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\nimport logging\n\nimport pupil_recording_interface as pri" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Set Pupil Core generation\n\nSet the generation of your Pupil Core device (1, 2 or 3)\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"pupil_gen = 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Set folder containing calibration\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"folder = \"~/pupil_capture_settings\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Set up stream configurations\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"configs = [\n pri.VideoStream.Config(\n device_type=\"uvc\",\n device_uid=f\"Pupil Cam{pupil_gen} ID2\",\n name=\"world\",\n resolution=(1280, 720),\n fps=30,\n pipeline=[pri.GazeMapper.Config(), pri.VideoDisplay.Config()],\n ),\n pri.VideoStream.Config(\n device_type=\"uvc\",\n device_uid=f\"Pupil Cam{pupil_gen} ID0\",\n name=\"eye0\",\n resolution=(320, 240) if pupil_gen == 1 else (192, 192),\n fps=120,\n color_format=\"gray\",\n pipeline=[\n pri.PupilDetector.Config(),\n pri.VideoDisplay.Config(flip=True),\n ],\n ),\n pri.VideoStream.Config(\n device_type=\"uvc\",\n device_uid=f\"Pupil Cam{pupil_gen} ID1\",\n name=\"eye1\",\n resolution=(320, 240) if pupil_gen == 1 else (192, 192),\n fps=120,\n color_format=\"gray\",\n pipeline=[pri.PupilDetector.Config(), pri.VideoDisplay.Config()],\n ),\n]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Set up logger\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"logging.basicConfig(\n stream=sys.stdout, level=logging.INFO, format=\"%(message)s\"\n)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Run manager\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>When running the script from the command line, press 'Ctrl+C' to stop the\n manager. When running from a Jupyter notebook, interrupt the kernel\n (*Kernel > Interrupt Kernel* or press 'Esc' and then twice 'i').</p></div>\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"with pri.StreamManager(configs, folder=folder) as manager:\n while not manager.stopped:\n if manager.all_streams_running:\n status = manager.format_status(\n \"pupil.confidence\", max_cols=72, sleep=0.1, nan_format=None,\n )\n print(\"\\r\" + status, end=\"\")\n\nprint(\"\\nStopped\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.15" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
65 changes: 65 additions & 0 deletions
65
_downloads/553e6445460593299cbe43e4bbf31c44/1_plot_gaze_pipeline.py
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,65 @@ | ||
""" | ||
.. _gaze_pipeline_example: | ||
Gaze mapping pipeline | ||
===================== | ||
This example shows how to perform post-hoc pupil detection, calibration marker | ||
detection, calibration and gaze mapping. | ||
.. note:: | ||
This example requires the dependencies for | ||
:ref:`pupil detection<pupil_detection_dependencies>` as well as | ||
``matplotlib``. | ||
""" | ||
import pupil_recording_interface as pri | ||
|
||
|
||
# %% | ||
# Set recording folder | ||
# -------------------- | ||
folder = pri.get_test_recording() | ||
|
||
# %% | ||
# Create readers for video streams | ||
# -------------------------------- | ||
world_reader = pri.VideoReader(folder) | ||
eye0_reader = pri.VideoReader(folder, stream="eye0", color_format="gray") | ||
eye1_reader = pri.VideoReader(folder, stream="eye1", color_format="gray") | ||
|
||
# %% | ||
# Detect pupils | ||
# ------------- | ||
pupil_detector_eye0 = pri.PupilDetector(camera_id=0) | ||
pupil_list_eye0 = pupil_detector_eye0.batch_run(eye0_reader) | ||
|
||
pupil_detector_eye1 = pri.PupilDetector(camera_id=1) | ||
pupil_list_eye1 = pupil_detector_eye1.batch_run(eye1_reader) | ||
|
||
# %% | ||
# Detect calibration markers | ||
# -------------------------- | ||
marker_detector = pri.CircleDetector() | ||
marker_list = marker_detector.batch_run(world_reader) | ||
|
||
# %% | ||
# Merge pupil data and run calibration | ||
# ------------------------------------ | ||
calibration = pri.Calibration(resolution=world_reader.resolution) | ||
pupil_list = pri.merge_pupils(pupil_list_eye0, pupil_list_eye1) | ||
calibration_result = calibration.batch_run(pupil_list, marker_list) | ||
|
||
# %% | ||
# Map gaze as dataset | ||
# ------------------- | ||
gaze_mapper = pri.GazeMapper(calibration=calibration_result) | ||
gaze = gaze_mapper.batch_run( | ||
pupil_list, return_type="dataset", info=world_reader.info | ||
) | ||
|
||
# %% | ||
# Plot gaze | ||
# --------- | ||
norm_pos = gaze.gaze_norm_pos.where(gaze.gaze_confidence_2d > 0.7) | ||
norm_pos.plot.line(x="time") |
180 changes: 180 additions & 0 deletions
180
_downloads/6de29d18e706bf0cd32d01aca6a0b99d/1_plot_gaze_pipeline.ipynb
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,180 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n\n# Gaze mapping pipeline\n\nThis example shows how to perform post-hoc pupil detection, calibration marker\ndetection, calibration and gaze mapping.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>This example requires the dependencies for\n `pupil detection<pupil_detection_dependencies>` as well as\n ``matplotlib``.</p></div>\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import pupil_recording_interface as pri" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Set recording folder\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"folder = pri.get_test_recording()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Create readers for video streams\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"world_reader = pri.VideoReader(folder)\neye0_reader = pri.VideoReader(folder, stream=\"eye0\", color_format=\"gray\")\neye1_reader = pri.VideoReader(folder, stream=\"eye1\", color_format=\"gray\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Detect pupils\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"pupil_detector_eye0 = pri.PupilDetector(camera_id=0)\npupil_list_eye0 = pupil_detector_eye0.batch_run(eye0_reader)\n\npupil_detector_eye1 = pri.PupilDetector(camera_id=1)\npupil_list_eye1 = pupil_detector_eye1.batch_run(eye1_reader)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Detect calibration markers\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"marker_detector = pri.CircleDetector()\nmarker_list = marker_detector.batch_run(world_reader)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Merge pupil data and run calibration\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"calibration = pri.Calibration(resolution=world_reader.resolution)\npupil_list = pri.merge_pupils(pupil_list_eye0, pupil_list_eye1)\ncalibration_result = calibration.batch_run(pupil_list, marker_list)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Map gaze as dataset\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"gaze_mapper = pri.GazeMapper(calibration=calibration_result)\ngaze = gaze_mapper.batch_run(\n pupil_list, return_type=\"dataset\", info=world_reader.info\n)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot gaze\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"norm_pos = gaze.gaze_norm_pos.where(gaze.gaze_confidence_2d > 0.7)\nnorm_pos.plot.line(x=\"time\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.15" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Binary file added
BIN
+32.3 KB
_downloads/6f1e7a639e0699d6164445b55e6c116d/auto_examples_jupyter.zip
Binary file not shown.
Oops, something went wrong.