Skip to main content

Python-based Wide-angle GAZE Recorder

Project description

pwgazer

Python-based, Wide-angle GAZE Recoder

pwgazer is a python-based eye tracker for wide angle camera (such as web camera). Postion and pose of human faces in the camera coordinate, relative position of pupils in the face, and gaze position on the PC screen are recorded.

Setup

Before using pwgazer, camera calibration must be performed and screen layout must be set. To calibrate the camera, first prepare a checkerboard. An example of checkerboard can be found in the resoureces folder (pwgazer/core/resouces/checker8x5.pdf). To use checker8x5.pdf, print it out on A4 paper and paste it onto a rigid board. With the camera to be used for the measurement available on the PC, execute the following command:

python -m pwgazer.app.CameraCalibration

Camera Calibration supports three sources: live camera, video file, and image file. Add images of the checkerboard taken at various angles and select "Run" menu to perform calibration. Calibration results are output as text and can be copied to the clipboard in the format of a configuration file. Prepare a blank text file (hereafter referred to as camera_parameters.cfg) and paste the calibration results into it. Don't close the application until pasted. Below is an example of the calibration results.

[Basic Parameters]
CAMERA_ID = 
RESOLUTION_HORIZ = 1920
RESOLUTION_VERT = 1080
DOWNSCALING = 0.5

[Calibration Parameters]
CAMERA_MATRIX_R0C0=1369.9104423575095
CAMERA_MATRIX_R0C1=0.0
CAMERA_MATRIX_R0C2=936.5660303951332
CAMERA_MATRIX_R1C0=0.0
CAMERA_MATRIX_R1C1=1371.2735355780137
CAMERA_MATRIX_R1C2=551.3859376282229
CAMERA_MATRIX_R2C0=0.0
CAMERA_MATRIX_R2C1=0.0
CAMERA_MATRIX_R2C2=1.0
DIST_COEFFS_R0C0=0.09818978049625876
DIST_COEFFS_R1C0=-0.048334067912787604
DIST_COEFFS_R2C0=0.0030492908222483615
DIST_COEFFS_R3C0=-2.1006330251313423e-05
DIST_COEFFS_R4C0=-2.1006330251313423e-05

[Screen Layout Parameters]
WIDTH=
HORIZ_RES=
OFFSET_X=
OFFSET_Y=
OFFSET_Z=
ROT_X=
ROT_Y=
ROT_Z=

[Filter]
FACE_FILTER = MA
FACE_FILTER_PARAM = 2,2
IRIS_FILTER = MA
IRIS_FILTER_PARAM = 2

As can be seen, "CAMERA_ID" in the "Basic Parameters" section and all entries in the "Screen Layout Parateters" section are not filled. "CAMERA_ID" can be checked with the following command. Note that the camera used for the measurement must be connected to the PC in advance.

python -m pwgazer.app.CameraSelector

This tool lists the cameras connected to the PC and allows you to see the images captured by each. The number on the list is the CAMERA_ID. The camera ID may change as cameras are added or removed.

To fill "Screen Layout Parameters" entries, run the following command.

python -m pwgazer.app.ScreenLayout

This command displays guide lines on the screen for measuring dimensions. After entering the measured values and clicking OK, the parameters are displayed in the format of a configuration file. Copy them and paste into the "Scrren Layout Parameters" section of camera_parameters.cfg.

If you want to use camera_parameters.cfg as your default configuration file, save it in pwgazer's configuration folder under the name CameraParam.cfg. The configuration folder is as follows:

  • %appdata%/pwgazer (Windows)
  • $HOME/.pwgazer (Mac/Linux)

Offline recording

Offline recording mode measures the gaze of the participant in the video files. Calibration task in which participants fixate on a known point on the screen must be recorded in the video. The following command performs an example of calibration task.

python -m pwgazer.demo.OfflineCalibrationDemo

This demo draws calibration target on the screen while capturing camera image. In each session, a CSV file and a MP4 movie file are created. The CSV file records location and timing of the calibration target. The MP4 file is a movie captured by the camera. The following command calculates calibration parameters using these files.

python -m pwgazer.app.OfflineCalibration

The OfflineCalibration command has several options. For example, CSV file, movie file and camear parameter configration file can be specified with command line options.

python -m pwgazer.app.OfflineCalibration --movie=cal.mp4 --cal_info=cal.csv --camera_param=camera_parameteres.cfg

Pwgazer requires 3D coordinates of facial feature points to estimate facial posture. These coordinate values are defined in the FaceModel.cfg file in pwgazer's configuration folder. To use other files, use --face_model option.

python -m pwgazer.app.OfflineCalibration --face_model=my_facemodel.cfg

The --iris_detector option specifies how the iris center is detected from the face image. Three detectors, peak, ert, and enet are included in the pwgazer package. The peak detector is fast in computation but very inaccurate especially in the vertical direction. The enet detector requires the most time for computation but has the most accurate of the three. The ert detector This detector is in the middle in terms of speed and accuracy.

python -m pwgazer.app.OfflineCalibration --iris_detector=enet

Calibration result is saved to a file with a .npz extension (e.g. cal_param.npz).

Batch mode is useful for processing multiple files at once. In batch mode, calibration results can be output without any GUI manipulation. Input movie file (--movie), calibration information (--cal_info), and output filename (--output) must be specified by commandline options.

python -m pwgazer.app.OfflineCalibration --movie=cal.mp4 --cal_info=cal.csv --output=cal_param.npz --batch

After the calibration result file is generated, the following command can be used to measure eye gaze for videos of the same participant in the same camera/screen configuration. Most commandline options are common to the OfflineCalibration.

python -m pwgazer.app.OfflineTracker

Realtime recording

Gaze measurement is a time-consuming process, taking much longer than one video frame. Therefore, offline recording mode is recommended. However, real-time recording is also supported if needed. The following command starts the realtime tracker. Similar to the offline tracker,

python -m pwgazer.app.RealtimeTracker

The following command runs a demo of realtime recording. PsychoPy and GazeParser are rquired to run the demo.

python -m pwgazer.demo.CalibrationDemo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pwgazer-1.0.0.tar.gz (99.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pwgazer-1.0.0-py3-none-any.whl (100.2 MB view details)

Uploaded Python 3

File details

Details for the file pwgazer-1.0.0.tar.gz.

File metadata

  • Download URL: pwgazer-1.0.0.tar.gz
  • Upload date:
  • Size: 99.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.8

File hashes

Hashes for pwgazer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 433ef984d18e73bec17cc56833686f08a0497cc346dbdcdfbf950c439b3f9671
MD5 a9a474efbedbbb3cb8a077c77456b725
BLAKE2b-256 775b673118d78a3c40d36ddd940d1dc936fb9820002247486ae9f80e2c9f61db

See more details on using hashes here.

File details

Details for the file pwgazer-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pwgazer-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 100.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.8

File hashes

Hashes for pwgazer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c764243e6e0faa97887844c428b7b06e9a5fbb80718ab61132829e347451cfe1
MD5 9d69f0b03950518b30cf39c3f49cfa30
BLAKE2b-256 bf43ba2b094eb5f6b94a08042097136187f9d5bffb8358b7d679afa91d9188d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page