visageSDK

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
VisageTracker.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
17 #ifndef __VisageTracker_h__
18 #define __VisageTracker_h__
19
20 #ifdef VISAGE_STATIC
21 #define VISAGE_DECLSPEC
22 #else
23
24 #ifdef VISAGE_EXPORTS
25 #define VISAGE_DECLSPEC __declspec(dllexport)
26 #else
27 #define VISAGE_DECLSPEC __declspec(dllimport)
28 #endif
29
30 #endif
31
32 #include "FaceData.h"
33 #include "SmoothingFilter.h"
34 #include "VisageConfiguration.h"
35
36 #ifdef WIN32
37 #ifndef NOMINMAX
38 #define NOMINMAX
39 #endif /* !NOMINMAX */
40 #include <windows.h>
41 #include <process.h>
42 #endif
43
44 #ifdef ANDROID
45 extern "C" {
46 VISAGE_DECLSPEC void _loadVisageVision();
47 }
48 #endif
49
50 #ifndef WIN32
51 #include <pthread.h>
52 #include <sys/types.h>
53 #define HANDLE pthread_t*
54 #endif
55
60 namespace VisageSDK
61 {
62
63 #ifndef ANDROID
64 int VISAGE_DECLSPEC initializeLicenseManager(const char *licenseKeyFileFolder);
65 #endif
66
71 const VISAGE_DECLSPEC char* getVisageSDKVersion(void);
72
73 #define TRACK_STAT_OFF 0
74 #define TRACK_STAT_OK 1
75 #define TRACK_STAT_RECOVERING 2
76 #define TRACK_STAT_INIT 3
77
78 #define VISAGE_CAMERA_UP 0
79 #define VISAGE_CAMERA_DOWN 1
80 #define VISAGE_CAMERA_LEFT 2
81 #define VISAGE_CAMERA_RIGHT 3
82
83 #define VISAGE_FRAMEGRABBER_FMT_RGB 0
84 #define VISAGE_FRAMEGRABBER_FMT_BGR 1
85 #define VISAGE_FRAMEGRABBER_FMT_LUMINANCE 2
86 #define VISAGE_FRAMEGRABBER_FMT_RGBA 3
87 #define VISAGE_FRAMEGRABBER_FMT_BGRA 4
88
89 #define VISAGE_FRAMEGRABBER_ORIGIN_TL 0
90 #define VISAGE_FRAMEGRABBER_ORIGIN_BL 1
91
92 class VisageTrackerInternal;
93 class Candide3Model;
94 class TrackerInternalInterface;
95 class TrackerGUIInterface;
96 class VisageDetector;
97 class ModelFitter;
98 class PoseEstimator;
99
260 class VISAGE_DECLSPEC VisageTracker
261 {
262 public:
283 VisageTracker(const char* trackerConfigFile);
284
287 virtual ~VisageTracker();
288
334 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);
335
346 void setTrackerConfiguration(const char* trackerConfigFile, bool au_fitting_disabled = false, bool mesh_fitting_disabled = false);
347
362 void setIPD(float value);
363
370 float getIPD();
371
377 void stop();
378
384 void reset();
385
389 const char* getSDKVersion();
390
395 VisageConfiguration getTrackerConfiguration();
396
403 void setTrackerConfiguration(VisageConfiguration &configuration);
404
405 #ifdef IOS
406
412 void setDataBundle(NSBundle *bundle);
413 #endif
414 private:
415 int Init(void);
416 void Finish(void);
417 bool shouldReset(int resetFlag);
418
419 static void processEyesClosure(const VsImage* frame, FDP* fdp, float* t, float* r, float* out);
420 static void GetPupilCoords(FDP* points, VsMat* eyes_coords, int w, int h);
421
422 TrackerGUIInterface *guiIface;
423 TrackerInternalInterface *internalIface;
424
425 float recovery_timeout; /* This value is used only in automatic initialisation mode. It is used when the tracker looses the face and can not detect any face in the frame. This value tells the tracker how long it should wait before considering that the current user is gone and initialising the full re-initialisation procedure. If the face is detected before this time elapses, the tracker considers that it is the same person and it recovers, i.e. continues tracking it using the previous settings. The time is expressed in milliseconds. */
426
427 friend class VisageFeaturesDetector;
428 friend class VisageTrackerInternal;
429
430 VsImage* frame_gray; // Current video frame converted to grayscale; all processing is done on grayscale images
431 VsImage* previous_frame_gray; // Previous video frame converted to grayscale; all processing is done on grayscale images
432
433 protected:
434 VsMat *smoothing_factors;
435 unsigned int enable_smoothing;
436 unsigned int temporally_denoise_input;
437
438 VsImage* frame_input; // Current video frame, input; may be color or grayscale
439
440 void terminateMT();
441
442 int frameCount; // frame count from beginning of tracking
443 double frameTime; // duration of one frame in milliseconds
444 long pts; // presentation time stamp
445 int pts_frame;
446
447 unsigned long initialTime;
448 unsigned long last_times[10];
449 int cnt;
450
451 volatile bool active;
452
453 private:
454 VisageConfiguration* m_Configuration;
455 VisageConfiguration* m_ConfigurationIntermediary;
456
457 long getCurrentTimeMs(bool init);
458 void deNoiseFrameGray();
459 bool grabFrame(bool init);
460
461 static void AugmentFDP(FDP* src, FDP* dst);
462 static void unProjectStuff(FDP* fp2D, FDP* fp3D, int w, int h, float f);
463 static void removeTransform(FDP* fp3D, FDP* fp3DR, const float* r, const float* t);
464 static void setPose(float pose[6], float t[3], float r[3]);
465 static float getAvgQuality(const FDP &fdp);
466
467 bool init_successful;
468
469 std::string configuration_filename; //tracker configuration file
470
471 #ifdef IOS
472 NSBundle *dataBundle;
473 #endif
474
475 volatile bool tracking_ok; //tracking status OK
476 float trackingFrameRate; // measured tracking frame rate
477
478 int m_width; //frame width
479 int m_height; //frame height
480 int m_format; //frame format for the frame image (RGB, BGR or LUMINANCE)
481
482 void initDetector();
483 void initModels();
484 void initTrackerInternal();
485
486 bool loadModel(Candide3Model **model, int modelType);
487
488 float m_IPD;
489
490 #if defined(IOS) || defined(ANDROID) || defined(MAC_OS_X) || defined(LINUX)
491 pthread_mutex_t track_mutex;
492 pthread_mutex_t config_mutex;
493 #endif
494
495 #ifdef WIN32
496 CRITICAL_SECTION track_mutex;
497 CRITICAL_SECTION config_mutex;
498 #endif
499
500 std::string vfd_data_path;
501 std::string vft_data_path;
502 std::string pr_data_path;
503 std::string er_data_path;
504 #ifdef EMSCRIPTEN
505 public: VisageDetector* m_DetectorBDFS;
506 private:
507 #else
508 VisageDetector* m_DetectorBDFS;
509 #endif
510
511 // pose estimator model
512 Candide3Model* model;
513 // au fitting model
514 Candide3Model* au_model;
515 // mesh fitting model
516 Candide3Model* mesh_model;
517
518 bool use_single_model;
519 bool use_pose_model;
520 bool use_au_model;
521 bool use_mesh_model;
522
523 bool au_fitting_disable;
524 bool mesh_fitting_disable;
525
526 bool inited;
527
528 long fg_pts;
529
530 int configChanged;
531
532 char m_trackCfgDataPath[1024];
533
534 FILE *log_file; //log file - used for debugging, set via log_filename configuration parameter
535
536 int m_maxFaces;
537
538 VisageTrackerInternal **tracker;
539 int* trackStatus;
540 };
541 }
542
543 #endif // __VisageTracker_h__
544
VisageSDK::VisageTracker
VisageTracker is a face tracker capable of tracking the head pose, facial features and gaze for multi...
Definition: VisageTracker.h:260
VisageSDK::VisageFeaturesDetector
Faces and facial features detector implementation.
Definition: VisageFeaturesDetector.h:106
VisageSDK::VisageConfiguration
VisageConfiguration is a class used to change, apply, load and save configuration parameters used by ...
Definition: VisageConfiguration.h:272
VisageSDK::getVisageSDKVersion
const VISAGE_DECLSPEC char * getVisageSDKVersion(void)
Returns visageSDK version and revision number.
VisageSDK::FaceData
Face data structure, used as container for all face tracking and detection results.
Definition: FaceData.h:259
VisageSDK::FDP
Feature points of a face.
Definition: FDP.h:191
VsImage
Image store container.
Definition: vs_core_types_c.h:460