Tobii Pro SDK Python API
calibration.py
1 def execute(eyetracker):
2  if eyetracker is None:
3  return
4 
5  # <BeginExample>
6  import time
7  import tobii_research as tr
8 
9  calibration = tr.ScreenBasedCalibration(eyetracker)
10 
11  # Enter calibration mode.
12  calibration.enter_calibration_mode()
13  print("Entered calibration mode for eye tracker with serial number {0}.".format(eyetracker.serial_number))
14 
15  # Define the points on screen we should calibrate at.
16  # The coordinates are normalized, i.e. (0.0, 0.0) is the upper left corner and (1.0, 1.0) is the lower right corner.
17  points_to_calibrate = [(0.5, 0.5), (0.1, 0.1), (0.1, 0.9), (0.9, 0.1), (0.9, 0.9)]
18 
19  for point in points_to_calibrate:
20  print("Show a point on screen at {0}.".format(point))
21 
22  # Wait a little for user to focus.
23  time.sleep(0.7)
24 
25  print("Collecting data at {0}.".format(point))
26  if calibration.collect_data(point[0], point[1]) != tr.CALIBRATION_STATUS_SUCCESS:
27  # Try again if it didn't go well the first time.
28  # Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
29  calibration.collect_data(point[0], point[1])
30 
31  print("Computing and applying calibration.")
32  calibration_result = calibration.compute_and_apply()
33  print("Compute and apply returned {0} and collected at {1} points.".
34  format(calibration_result.status, len(calibration_result.calibration_points)))
35 
36  # Analyze the data and maybe remove points that weren't good.
37  recalibrate_point = (0.1, 0.1)
38  print("Removing calibration point at {0}.".format(recalibrate_point))
39  calibration.discard_data(recalibrate_point[0], recalibrate_point[1])
40 
41  # Redo collection at the discarded point
42  print("Show a point on screen at {0}.".format(recalibrate_point))
43  calibration.collect_data(recalibrate_point[0], recalibrate_point[1])
44 
45  # Compute and apply again.
46  print("Computing and applying calibration.")
47  calibration_result = calibration.compute_and_apply()
48  print("Compute and apply returned {0} and collected at {1} points.".
49  format(calibration_result.status, len(calibration_result.calibration_points)))
50 
51  # See that you're happy with the result.
52 
53  # The calibration is done. Leave calibration mode.
54  calibration.leave_calibration_mode()
55 
56  print("Left calibration mode.")
57  # <EndExample>