.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/online/4_calibrate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_online_4_calibrate.py: .. _calibration_example: Calibrate gaze mapping ====================== This examples shows how to calibrate the gaze mapper with a connected Pupil Core headset. .. note:: This example requires the dependencies for :ref:`streaming` and :ref:`pupil detection`. .. GENERATED FROM PYTHON SOURCE LINES 18-24 .. code-block:: default import sys import logging import pupil_recording_interface as pri .. GENERATED FROM PYTHON SOURCE LINES 25-29 Set Pupil Core generation ------------------------- Set the generation of your Pupil Core device (1, 2 or 3) .. GENERATED FROM PYTHON SOURCE LINES 29-31 .. code-block:: default pupil_gen = 2 .. GENERATED FROM PYTHON SOURCE LINES 32-34 Set folder for saving calibration --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: default folder = "~/pupil_capture_settings" .. GENERATED FROM PYTHON SOURCE LINES 37-39 Set up stream configurations ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 39-76 .. code-block:: default configs = [ pri.VideoStream.Config( device_type="uvc", device_uid=f"Pupil Cam{pupil_gen} ID2", name="world", resolution=(1280, 720), fps=30, pipeline=[ pri.CircleDetector.Config(paused=True), pri.Calibration.Config(save=True, folder=folder), pri.GazeMapper.Config(), pri.VideoDisplay.Config(), ], ), pri.VideoStream.Config( device_type="uvc", device_uid=f"Pupil Cam{pupil_gen} ID0", name="eye0", resolution=(320, 240) if pupil_gen == 1 else (192, 192), fps=120, color_format="gray", pipeline=[ pri.PupilDetector.Config(), pri.VideoDisplay.Config(flip=True), ], ), pri.VideoStream.Config( device_type="uvc", device_uid=f"Pupil Cam{pupil_gen} ID1", name="eye1", resolution=(320, 240) if pupil_gen == 1 else (192, 192), fps=120, color_format="gray", pipeline=[pri.PupilDetector.Config(), pri.VideoDisplay.Config()], ), ] .. GENERATED FROM PYTHON SOURCE LINES 77-79 Set up logger ------------- .. GENERATED FROM PYTHON SOURCE LINES 79-83 .. code-block:: default logging.basicConfig( stream=sys.stdout, level=logging.INFO, format="%(message)s" ) .. GENERATED FROM PYTHON SOURCE LINES 84-89 Run manager ----------- With one of the video windows in focus, press 'c' to start collecting calibration data, then 'c' again to calculate the calibration from the collected data. Press 'q' to quit. .. GENERATED FROM PYTHON SOURCE LINES 89-117 .. code-block:: default collecting = False with pri.StreamManager(configs) as manager: while not manager.stopped: if manager.keypresses._getvalue(): key = manager.keypresses.popleft() if key.lower() == "c": if not collecting: print("Collecting calibration data...") manager.send_notification( {"resume_process": "world.CircleDetector"}, streams=["world"], ) manager.send_notification( {"collect_calibration_data": True}, streams=["world"], ) collecting = True else: print("Calculating calibration...") manager.send_notification( {"pause_process": "world.CircleDetector"}, streams=["world"], ) manager.send_notification({"calculate_calibration": True}) collecting = False elif key.lower() == "q": break print("\nStopped") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_online_4_calibrate.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 4_calibrate.py <4_calibrate.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 4_calibrate.ipynb <4_calibrate.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_