Tobii Pro SDK C API
calibration.c
#include <stdio.h>
#if _WIN32 || _WIN64
#include <windows.h>
static void sleep_ms(int time) {
Sleep(time);
}
#else
#include <unistd.h>
static void sleep_ms(int time) {
usleep(time * 1000);
}
#endif
void calibration_example(TobiiResearchEyeTracker* eyetracker) {
/* Enter calibration mode. */
char* serial_number = NULL;
tobii_research_get_serial_number(eyetracker, &serial_number);
printf("Entered calibration mode for eye tracker with serial number %s \n.", serial_number);
/* Define the points on screen we should calibrate at. */
/* 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. */
{
#define NUM_OF_POINTS 5U
TobiiResearchNormalizedPoint2D points_to_calibrate[NUM_OF_POINTS] = \
{{0.5f, 0.5f}, {0.1f, 0.1f}, {0.1f, 0.9f}, {0.9f, 0.1f}, {0.9f, 0.9f}};
size_t i = 0;
for(; i < NUM_OF_POINTS; i++) {
TobiiResearchNormalizedPoint2D* point = &points_to_calibrate[i];
printf("Show a point on screen at (%f,%f).\n", point->x, point->y);
// Wait a little for user to focus.
sleep_ms(700);
printf("Collecting data at (%f,%f).\n", point->x, point->y);
/* Try again if it didn't go well the first time. */
/* Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply. */
}
}
printf("Computing and applying calibration.\n");
TobiiResearchCalibrationResult* calibration_result = NULL;
status = tobii_research_screen_based_calibration_compute_and_apply(eyetracker, &calibration_result);
if (status == TOBII_RESEARCH_STATUS_OK && calibration_result->status == TOBII_RESEARCH_CALIBRATION_SUCCESS) {
printf("Compute and apply returned %i and collected at %zu points.\n", status, calibration_result->calibration_point_count);
} else {
printf("Calibration failed!\n");
}
/* Free calibration result when done using it */
/* Analyze the data and maybe remove points that weren't good. */
TobiiResearchNormalizedPoint2D* recalibrate_point = &points_to_calibrate[1];
printf("Removing calibration point at (%f,%f).\n", recalibrate_point->x, recalibrate_point->y);
status = tobii_research_screen_based_calibration_discard_data(eyetracker, recalibrate_point->x, recalibrate_point->y);
/* Redo collection at the discarded point */
printf("Show a point on screen at (%f,%f).\n", recalibrate_point->x, recalibrate_point->y);
tobii_research_screen_based_calibration_collect_data(eyetracker, recalibrate_point->x, recalibrate_point->y);
/* Compute and apply again. */
printf("Computing and applying calibration.\n");
status = tobii_research_screen_based_calibration_compute_and_apply(eyetracker, &calibration_result);
if (status == TOBII_RESEARCH_STATUS_OK && calibration_result->status == TOBII_RESEARCH_CALIBRATION_SUCCESS) {
printf("Compute and apply returned %i and collected at %zu points.\n", status, calibration_result->calibration_point_count);
} else {
printf("Calibration failed!\n");
}
/* Free calibration result when done using it */
/* See that you're happy with the result. */
}
/* The calibration is done. Leave calibration mode. */
printf("Left calibration mode.\n");
}
TobiiResearchNormalizedPoint2D::y
float y
Definition: tobii_research.h:387
TobiiResearchNormalizedPoint2D
Definition: tobii_research.h:379
tobii_research_screen_based_calibration_compute_and_apply
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_screen_based_calibration_compute_and_apply(TobiiResearchEyeTracker *eyetracker, TobiiResearchCalibrationResult **result)
Uses the collected data and tries to compute calibration parameters.
tobii_research_get_serial_number
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_get_serial_number(TobiiResearchEyeTracker *eyetracker, char **serial_number)
Gets the serial number of the eye tracker. All physical eye trackers have a unique serial number.
tobii_research_calibration.h
Functionality for implementing calibration.
tobii_research_eyetracker.h
Functionality for an eye tracker.
tobii_research_free_string
TOBII_RESEARCH_API void TOBII_RESEARCH_CALL tobii_research_free_string(char *str)
Free memory allocation for a string allocated by the SDK.
tobii_research_screen_based_calibration_collect_data
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_screen_based_calibration_collect_data(TobiiResearchEyeTracker *eyetracker, float x, float y)
Starts collecting data for a calibration point.
TOBII_RESEARCH_CALIBRATION_SUCCESS
@ TOBII_RESEARCH_CALIBRATION_SUCCESS
Definition: tobii_research_calibration.h:34
TobiiResearchEyeTracker
struct TobiiResearchEyeTracker TobiiResearchEyeTracker
Definition: tobii_research.h:310
TobiiResearchCalibrationResult
Definition: tobii_research_calibration.h:139
TobiiResearchNormalizedPoint2D::x
float x
Definition: tobii_research.h:383
TobiiResearchCalibrationResult::status
TobiiResearchCalibrationStatus status
Definition: tobii_research_calibration.h:151
tobii_research_screen_based_calibration_enter_calibration_mode
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_screen_based_calibration_enter_calibration_mode(TobiiResearchEyeTracker *eyetracker)
Enters the screen based calibration mode and the eye tracker is made ready for collecting data and ca...
tobii_research_screen_based_calibration_leave_calibration_mode
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_screen_based_calibration_leave_calibration_mode(TobiiResearchEyeTracker *eyetracker)
Leaves the screen based calibration mode.
tobii_research_screen_based_calibration_discard_data
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_screen_based_calibration_discard_data(TobiiResearchEyeTracker *eyetracker, float x, float y)
Removes the collected data associated with a specific calibration point.
tobii_research_free_screen_based_calibration_result
TOBII_RESEARCH_API void TOBII_RESEARCH_CALL tobii_research_free_screen_based_calibration_result(TobiiResearchCalibrationResult *result)
Free memory allocation for the calibration result received via tobii_research_screen_based_calibratio...
TobiiResearchCalibrationResult::calibration_point_count
size_t calibration_point_count
Definition: tobii_research_calibration.h:147
TOBII_RESEARCH_STATUS_OK
@ TOBII_RESEARCH_STATUS_OK
Definition: tobii_research.h:49
TobiiResearchStatus
TobiiResearchStatus
Definition: tobii_research.h:45