Tobii Pro SDK Python API
tobii_research.ScreenBasedMonocularCalibration Class Reference

Provides methods and properties for managing monocular and bi-monocular calibrations for screen based eye trackers. More...

Inherits object.

Public Member Functions

def __init__ (self, eyetracker)
 Initialize a new ScreenBasedMonocularCalibration object from an existing EyeTracker object.
 
def enter_calibration_mode (self)
 Enters the calibration mode and the eye tracker is made ready for collecting data and calculating new calibrations. More...
 
def leave_calibration_mode (self)
 Leaves the calibration mode. More...
 
def collect_data (self, x, y, eye_to_calibrate)
 Collects data for a calibration point for the selected eye(s). More...
 
def discard_data (self, x, y, eye_to_calibrate)
 Removes the collected data for the specified eye(s) and calibration point. More...
 
def compute_and_apply (self)
 Uses the collected data and tries to compute calibration parameters. More...
 

Detailed Description

Provides methods and properties for managing monocular and bi-monocular calibrations for screen based eye trackers.

This type of calibration is not supported by all eye trackers. Check the DeviceCapabilities of the eye tracker first!

Member Function Documentation

def tobii_research.ScreenBasedMonocularCalibration.collect_data (   self,
  x,
  y,
  eye_to_calibrate 
)

Collects data for a calibration point for the selected eye(s).

The point argument is the point on the display the user is assumed to be looking at and is given in the active display area coordinate system. See find_all_eyetrackers or EyeTracker.__init__ on how to create an EyeTracker object.

1 import time
2 import tobii_research as tr
3 
4 calibration = tr.ScreenBasedMonocularCalibration(eyetracker)
5 
6 # Enter calibration mode.
7 calibration.enter_calibration_mode()
8 print("Entered calibration mode for eye tracker with serial number {0}.".format(eyetracker.serial_number))
9 
10 # Define the points on screen we should calibrate at.
11 # 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.
12 points_to_calibrate = [(0.5, 0.5), (0.1, 0.1), (0.1, 0.9), (0.9, 0.1), (0.9, 0.9)]
13 
14 # Select which eye should be calibrate ie tr.SELECTED_EYE_LEFT, tr.SELECTED_EYE_RIGHT or tr.SELECTED_EYE_BOTH
15 eye_to_calibrate = tr.SELECTED_EYE_BOTH
16 
17 for point in points_to_calibrate:
18  print("Show a point on screen at {0}.".format(point))
19 
20  # Wait a little for user to focus.
21  time.sleep(0.7)
22 
23  print("Collecting data at {0}.".format(point))
24  if calibration.collect_data(point[0], point[1], eye_to_calibrate) == tr.CALIBRATION_STATUS_FAILURE:
25  # Try again if it didn't go well the first time.
26  # Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
27  calibration.collect_data(point[0], point[1], eye_to_calibrate)
28 
29 print("Computing and applying calibration.")
30 calibration_result = calibration.compute_and_apply()
31 print("Compute and apply returned {0} and collected at {1} points.".
32  format(calibration_result.status, len(calibration_result.calibration_points)))
33 
34 # Analyze the data and maybe remove points that weren't good.
35 recalibrate_point = (0.1, 0.1)
36 print("Removing calibration point at {0}.".format(recalibrate_point))
37 calibration.discard_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
38 
39 # Redo collection at the discarded point
40 print("Show a point on screen at {0}.".format(recalibrate_point))
41 calibration.collect_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
42 
43 # Compute and apply again.
44 print("Computing and applying calibration.")
45 calibration_result = calibration.compute_and_apply()
46 print("Compute and apply returned {0} and collected at {1} points.".
47  format(calibration_result.status, len(calibration_result.calibration_points)))
48 
49 # See that you're happy with the result.
50 
51 # The calibration is done. Leave calibration mode.
52 calibration.leave_calibration_mode()
53 
54 print("Left calibration mode.")
Parameters
xNormalized x coordinate on the active display area.
yNormalized y coordinate on the active display area.
eye_to_calibrateSelected eye for data collection.
Exceptions
EyeTrackerConnectionFailedError
EyeTrackerFeatureNotSupportedError
EyeTrackerInvalidOperationError
EyeTrackerLicenseError
EyeTrackerInternalError
Returns
CALIBRATION_STATUS_SUCCESS on success for both eyes. CALIBRATION_STATUS_SUCCESS_LEFT_EYE on success for the left_eye. CALIBRATION_STATUS_SUCCESS_RIGHT_EYE on success for the right eye. CALIBRATION_STATUS_FAILURE on failure.
def tobii_research.ScreenBasedMonocularCalibration.compute_and_apply (   self)

Uses the collected data and tries to compute calibration parameters.

If the calculation is successful, the result is applied to the eye tracker. If there is insufficient data to compute a new calibration or if the collected data is not good enough then calibration fails and will not be applied. See find_all_eyetrackers or EyeTracker.__init__ on how to create an EyeTracker object.

1 import time
2 import tobii_research as tr
3 
4 calibration = tr.ScreenBasedMonocularCalibration(eyetracker)
5 
6 # Enter calibration mode.
7 calibration.enter_calibration_mode()
8 print("Entered calibration mode for eye tracker with serial number {0}.".format(eyetracker.serial_number))
9 
10 # Define the points on screen we should calibrate at.
11 # 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.
12 points_to_calibrate = [(0.5, 0.5), (0.1, 0.1), (0.1, 0.9), (0.9, 0.1), (0.9, 0.9)]
13 
14 # Select which eye should be calibrate ie tr.SELECTED_EYE_LEFT, tr.SELECTED_EYE_RIGHT or tr.SELECTED_EYE_BOTH
15 eye_to_calibrate = tr.SELECTED_EYE_BOTH
16 
17 for point in points_to_calibrate:
18  print("Show a point on screen at {0}.".format(point))
19 
20  # Wait a little for user to focus.
21  time.sleep(0.7)
22 
23  print("Collecting data at {0}.".format(point))
24  if calibration.collect_data(point[0], point[1], eye_to_calibrate) == tr.CALIBRATION_STATUS_FAILURE:
25  # Try again if it didn't go well the first time.
26  # Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
27  calibration.collect_data(point[0], point[1], eye_to_calibrate)
28 
29 print("Computing and applying calibration.")
30 calibration_result = calibration.compute_and_apply()
31 print("Compute and apply returned {0} and collected at {1} points.".
32  format(calibration_result.status, len(calibration_result.calibration_points)))
33 
34 # Analyze the data and maybe remove points that weren't good.
35 recalibrate_point = (0.1, 0.1)
36 print("Removing calibration point at {0}.".format(recalibrate_point))
37 calibration.discard_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
38 
39 # Redo collection at the discarded point
40 print("Show a point on screen at {0}.".format(recalibrate_point))
41 calibration.collect_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
42 
43 # Compute and apply again.
44 print("Computing and applying calibration.")
45 calibration_result = calibration.compute_and_apply()
46 print("Compute and apply returned {0} and collected at {1} points.".
47  format(calibration_result.status, len(calibration_result.calibration_points)))
48 
49 # See that you're happy with the result.
50 
51 # The calibration is done. Leave calibration mode.
52 calibration.leave_calibration_mode()
53 
54 print("Left calibration mode.")
Exceptions
EyeTrackerConnectionFailedError
EyeTrackerFeatureNotSupportedError
EyeTrackerInvalidOperationError
EyeTrackerLicenseError
EyeTrackerInternalError
Returns
A CalibrationResult object.
def tobii_research.ScreenBasedMonocularCalibration.discard_data (   self,
  x,
  y,
  eye_to_calibrate 
)

Removes the collected data for the specified eye(s) and calibration point.

See find_all_eyetrackers or EyeTracker.__init__ on how to create an EyeTracker object.

1 import time
2 import tobii_research as tr
3 
4 calibration = tr.ScreenBasedMonocularCalibration(eyetracker)
5 
6 # Enter calibration mode.
7 calibration.enter_calibration_mode()
8 print("Entered calibration mode for eye tracker with serial number {0}.".format(eyetracker.serial_number))
9 
10 # Define the points on screen we should calibrate at.
11 # 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.
12 points_to_calibrate = [(0.5, 0.5), (0.1, 0.1), (0.1, 0.9), (0.9, 0.1), (0.9, 0.9)]
13 
14 # Select which eye should be calibrate ie tr.SELECTED_EYE_LEFT, tr.SELECTED_EYE_RIGHT or tr.SELECTED_EYE_BOTH
15 eye_to_calibrate = tr.SELECTED_EYE_BOTH
16 
17 for point in points_to_calibrate:
18  print("Show a point on screen at {0}.".format(point))
19 
20  # Wait a little for user to focus.
21  time.sleep(0.7)
22 
23  print("Collecting data at {0}.".format(point))
24  if calibration.collect_data(point[0], point[1], eye_to_calibrate) == tr.CALIBRATION_STATUS_FAILURE:
25  # Try again if it didn't go well the first time.
26  # Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
27  calibration.collect_data(point[0], point[1], eye_to_calibrate)
28 
29 print("Computing and applying calibration.")
30 calibration_result = calibration.compute_and_apply()
31 print("Compute and apply returned {0} and collected at {1} points.".
32  format(calibration_result.status, len(calibration_result.calibration_points)))
33 
34 # Analyze the data and maybe remove points that weren't good.
35 recalibrate_point = (0.1, 0.1)
36 print("Removing calibration point at {0}.".format(recalibrate_point))
37 calibration.discard_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
38 
39 # Redo collection at the discarded point
40 print("Show a point on screen at {0}.".format(recalibrate_point))
41 calibration.collect_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
42 
43 # Compute and apply again.
44 print("Computing and applying calibration.")
45 calibration_result = calibration.compute_and_apply()
46 print("Compute and apply returned {0} and collected at {1} points.".
47  format(calibration_result.status, len(calibration_result.calibration_points)))
48 
49 # See that you're happy with the result.
50 
51 # The calibration is done. Leave calibration mode.
52 calibration.leave_calibration_mode()
53 
54 print("Left calibration mode.")
Parameters
xNormalized x coordinate on the active display area.
yNormalized y coordinate on the active display area.
eye_to_calibrateSelected eye for data discarding.
Exceptions
EyeTrackerConnectionFailedError
EyeTrackerFeatureNotSupportedError
EyeTrackerInvalidOperationError
EyeTrackerLicenseError
EyeTrackerInternalError
def tobii_research.ScreenBasedMonocularCalibration.enter_calibration_mode (   self)

Enters the calibration mode and the eye tracker is made ready for collecting data and calculating new calibrations.

See find_all_eyetrackers or EyeTracker.__init__ on how to create an EyeTracker object.

1 import time
2 import tobii_research as tr
3 
4 calibration = tr.ScreenBasedMonocularCalibration(eyetracker)
5 
6 # Enter calibration mode.
7 calibration.enter_calibration_mode()
8 print("Entered calibration mode for eye tracker with serial number {0}.".format(eyetracker.serial_number))
9 
10 # Define the points on screen we should calibrate at.
11 # 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.
12 points_to_calibrate = [(0.5, 0.5), (0.1, 0.1), (0.1, 0.9), (0.9, 0.1), (0.9, 0.9)]
13 
14 # Select which eye should be calibrate ie tr.SELECTED_EYE_LEFT, tr.SELECTED_EYE_RIGHT or tr.SELECTED_EYE_BOTH
15 eye_to_calibrate = tr.SELECTED_EYE_BOTH
16 
17 for point in points_to_calibrate:
18  print("Show a point on screen at {0}.".format(point))
19 
20  # Wait a little for user to focus.
21  time.sleep(0.7)
22 
23  print("Collecting data at {0}.".format(point))
24  if calibration.collect_data(point[0], point[1], eye_to_calibrate) == tr.CALIBRATION_STATUS_FAILURE:
25  # Try again if it didn't go well the first time.
26  # Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
27  calibration.collect_data(point[0], point[1], eye_to_calibrate)
28 
29 print("Computing and applying calibration.")
30 calibration_result = calibration.compute_and_apply()
31 print("Compute and apply returned {0} and collected at {1} points.".
32  format(calibration_result.status, len(calibration_result.calibration_points)))
33 
34 # Analyze the data and maybe remove points that weren't good.
35 recalibrate_point = (0.1, 0.1)
36 print("Removing calibration point at {0}.".format(recalibrate_point))
37 calibration.discard_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
38 
39 # Redo collection at the discarded point
40 print("Show a point on screen at {0}.".format(recalibrate_point))
41 calibration.collect_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
42 
43 # Compute and apply again.
44 print("Computing and applying calibration.")
45 calibration_result = calibration.compute_and_apply()
46 print("Compute and apply returned {0} and collected at {1} points.".
47  format(calibration_result.status, len(calibration_result.calibration_points)))
48 
49 # See that you're happy with the result.
50 
51 # The calibration is done. Leave calibration mode.
52 calibration.leave_calibration_mode()
53 
54 print("Left calibration mode.")
Exceptions
EyeTrackerConnectionFailedError
EyeTrackerFeatureNotSupportedError
EyeTrackerInvalidOperationError
EyeTrackerLicenseError
EyeTrackerInternalError
def tobii_research.ScreenBasedMonocularCalibration.leave_calibration_mode (   self)

Leaves the calibration mode.

See find_all_eyetrackers or EyeTracker.__init__ on how to create an EyeTracker object.

1 import time
2 import tobii_research as tr
3 
4 calibration = tr.ScreenBasedMonocularCalibration(eyetracker)
5 
6 # Enter calibration mode.
7 calibration.enter_calibration_mode()
8 print("Entered calibration mode for eye tracker with serial number {0}.".format(eyetracker.serial_number))
9 
10 # Define the points on screen we should calibrate at.
11 # 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.
12 points_to_calibrate = [(0.5, 0.5), (0.1, 0.1), (0.1, 0.9), (0.9, 0.1), (0.9, 0.9)]
13 
14 # Select which eye should be calibrate ie tr.SELECTED_EYE_LEFT, tr.SELECTED_EYE_RIGHT or tr.SELECTED_EYE_BOTH
15 eye_to_calibrate = tr.SELECTED_EYE_BOTH
16 
17 for point in points_to_calibrate:
18  print("Show a point on screen at {0}.".format(point))
19 
20  # Wait a little for user to focus.
21  time.sleep(0.7)
22 
23  print("Collecting data at {0}.".format(point))
24  if calibration.collect_data(point[0], point[1], eye_to_calibrate) == tr.CALIBRATION_STATUS_FAILURE:
25  # Try again if it didn't go well the first time.
26  # Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
27  calibration.collect_data(point[0], point[1], eye_to_calibrate)
28 
29 print("Computing and applying calibration.")
30 calibration_result = calibration.compute_and_apply()
31 print("Compute and apply returned {0} and collected at {1} points.".
32  format(calibration_result.status, len(calibration_result.calibration_points)))
33 
34 # Analyze the data and maybe remove points that weren't good.
35 recalibrate_point = (0.1, 0.1)
36 print("Removing calibration point at {0}.".format(recalibrate_point))
37 calibration.discard_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
38 
39 # Redo collection at the discarded point
40 print("Show a point on screen at {0}.".format(recalibrate_point))
41 calibration.collect_data(recalibrate_point[0], recalibrate_point[1], eye_to_calibrate)
42 
43 # Compute and apply again.
44 print("Computing and applying calibration.")
45 calibration_result = calibration.compute_and_apply()
46 print("Compute and apply returned {0} and collected at {1} points.".
47  format(calibration_result.status, len(calibration_result.calibration_points)))
48 
49 # See that you're happy with the result.
50 
51 # The calibration is done. Leave calibration mode.
52 calibration.leave_calibration_mode()
53 
54 print("Left calibration mode.")
Exceptions
EyeTrackerConnectionFailedError
EyeTrackerFeatureNotSupportedError
EyeTrackerInvalidOperationError
EyeTrackerLicenseError
EyeTrackerInternalError