visageSDK
VisageGazeTracker.h
1 //
3 // (c) Visage Technologies AB 2002 - 2023 All rights reserved.
4 //
5 // This file is part of visage|SDK(tm).
6 // Unauthorized copying of this file, via any medium is strictly prohibited.
7 //
8 // No warranty, explicit or implicit, provided.
9 //
10 // This is proprietary software. No part of this software may be used or
11 // reproduced in any form or by any means otherwise than in accordance with
12 // any written license granted by Visage Technologies AB.
13 //
15 
16 #ifndef VISAGEGAZETRACKER_H
17 #define VISAGEGAZETRACKER_H
18 
19 #include "ScreenSpaceGazeMapping.h"
20 #include "VisageGazeEstimation.h"
21 #include "TrackerGazeCalibrator.h"
22 #include "VisageTracker.h"
23 #include "GazeQualityCalculator.h"
24 
25 
26 #ifdef VISAGE_STATIC
27  #define VISAGE_GAZE_DECLSPEC
28 #else
29 
30  #ifdef VISAGE_GAZE_EXPORTS
31  #define VISAGE_GAZE_DECLSPEC __declspec(dllexport)
32  #else
33  #define VISAGE_GAZE_DECLSPEC __declspec(dllimport)
34  #endif
35 
36 #endif
37 
38 namespace VisageSDK
39 {
44 const VISAGE_DECLSPEC char* getVisageSDKVersion(void);
45 
114 class VISAGE_GAZE_DECLSPEC VisageGazeTracker : public VisageTracker
115 {
116  public:
117 
124  VisageGazeTracker(const char* trackerConfigFile);
125 
126  /* Constructor.
127  *
128  * @param oglInterface the TrackerOpenGLInterface object or NULL if not used.
129  * @param guiInterface the TrackerGUIInterface object or NULL if not used; in that case the tracker will only function in fully automatic mode. Semi-automatic modes require TrackerGUIInterface to be implemented.
130  * @param trackerConfigFile the name of the tracker configuration file (.cfg; default configuration files are provided in \if IOS_DOXY <a href="../../Samples/iOS/data">Samples/iOS/data</a> \elseif ANDROID_DOXY <a href="../../Samples/Android/data">Samples/Android/VisageTrackerUnityDemo/data</a>
131  * Constructor must be called with the full path to the configuration file. The configuration file is in the same directory as other data files needed by the tracker. Because it is in the same directory its path can be parsed to set the path for the other data files.
132  * \else Samples/OpenGL/data/FaceTracker2 \endif; for further details see <a href="../VisageTracker Configuration Manual.pdf">VisageTracker Configuration Manual</a>\if IOS_DOXY and section on <a href="../../doc/creatingxc.html#config_selection">device-specific configuration selection</a>.\endif).
133  * @see TrackerOpenGLInterface
134  * @see TrackerGUIInterface
135  */
136  //VisageGazeTracker(TrackerOpenGLInterface *oglInterface, TrackerGUIInterface *guiInterface, const char* trackerConfigFile);
137 
141 
142 
149  void InitOnlineGazeCalibration();
150 
164  void AddGazeCalibrationPoint(float x, float y);
165 
172  void FinalizeOnlineGazeCalibration();
173 
185  void InitOfflineGazeCalibration(ScreenSpaceGazeRepository* calibrator);
186 
200  float GetGazeEstimations(ScreenSpaceGazeRepository* repository/*, float* covariance = 0, float* headTranslation = 0, float* headRotation = 0, float* trackingPerc = 0*/);
201 
202  virtual int* track(int frameWidth, int frameHeight, const char* p_imageData, FaceData* facedata, int format = VISAGE_FRAMEGRABBER_FMT_RGB, int origin = VISAGE_FRAMEGRABBER_ORIGIN_TL, int widthStep = 0, long timeStamp = -1, int maxFaces = 1);
203 
204  void SetResolution(int width, int height);
205  void SetGazeViewportSize(int w, int h);
206  void SetGazeCenter(float x, float y);
207 
208  ScreenSpaceGazeRepository* GetCalibrator();
209  bool IsRealTime();
210  bool IsCalibrated();
211 
212  private:
213 
214  FaceData* trackingData;
215  int trackStatus;
216 
217  ScreenSpaceGazeRepository* estimations;
218  ScreenSpaceGazeRepository* calibrator;
219 
220  GazeEstimationPredictor* lxpredictor;
221  GazeEstimationPredictor* rxpredictor;
222 
223  GazeEstimationPredictor* lypredictor;
224  GazeEstimationPredictor* rypredictor;
225 
226  bool isRealTime;
227  bool isCalibrated;
228  bool predicting;
229 
230  void addOfflineScreenSpaceGazePoint();
231  void calculateOnlineScreenSpaceGaze();
232 
233  ScreenSpaceGazeData Predict(EyeData& data);
234  void CalculateQuality(float& error_x, float& error_y);
235  void smoothGazeData();
236  void smoothGazeEstimations();
237 
238  int frameIndex;
239 
240  long lastTimestamp;
241 
242  static int lew;
243  static int leh;
244  static int rew;
245  static int reh;
246 
247  int width;
248  int height;
249 
250  int nCalib;
251 
252  float prev_x;
253  float prev_y;
254 
255  float initGazeX;
256  float initGazeY;
257 
258  float bestD[2];
259 
260  int resolution[2];
261 
262  float avgCalibHeadTranslation[3];
263  float avgCalibHeadRotation[3];
264 
265  SessionQuality* sessionQuality;
266  SmoothingFilter *sf;
267 };
268 }
269 #endif
VisageTracker is a face tracker capable of tracking the head pose, facial features and gaze for multi...
Data repository holding ScreenSpaceGazeData objects in offline screen space gaze tracking mode...
ScreenSpaceGazeData is a container structure used to hold the gaze point location, current state of screen space gaze tracking system and gaze tracking estimation quality parameters for the current frame.
VisageGazeTracker extends VisageTracker functionality, adding screen space gaze tracking on top of fa...
Namespace.
Definition: win_header.h:1
const VISAGE_DECLSPEC char * getVisageSDKVersion(void)
Returns visageSDK version and revision number.
Face data structure, used as container for all face tracking and detection results.
Definition: FaceData.h:259