Tobii Pro SDK Python API
calibration_data.py
1 def execute(eyetracker):
2  if eyetracker is None:
3  return
4  # <BeginExample>
5  filename = "saved_calibration.bin"
6 
7  # Save the calibration to file.
8  with open(filename, "wb") as f:
9  calibration_data = eyetracker.retrieve_calibration_data()
10 
11  # None is returned on empty calibration.
12  if calibration_data is not None:
13  print("Saving calibration to file for eye tracker with serial number {0}.".format(eyetracker.serial_number))
14  f.write(eyetracker.retrieve_calibration_data())
15  else:
16  print("No calibration available for eye tracker with serial number {0}.".format(eyetracker.serial_number))
17 
18  # Read the calibration from file.
19  with open(filename, "rb") as f:
20  calibration_data = f.read()
21 
22  # Don't apply empty calibrations.
23  if len(calibration_data) > 0:
24  print("Applying calibration on eye tracker with serial number {0}.".format(eyetracker.serial_number))
25  eyetracker.apply_calibration_data(calibration_data)
26  # <EndExample>
27 
28  # Cleanup
29  import os
30  try:
31  os.remove(filename)
32  except OSError:
33  pass