faceLiveness.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef FACELIVENESS_H
  2. #define FACELIVENESS_H
  3. #include <QWidget>
  4. #include <QMovie>
  5. #include <QTimer>
  6. #include <thread>
  7. #include <mutex>
  8. #include <opencv2/opencv.hpp>
  9. #include "CLiveViodeProc.h"
  10. #include "CHttpBll.h"
  11. //SHAKE,BLINK,NOD
  12. namespace ACTION_TYPE
  13. {
  14. const QString AT_BLINK = "BLINK";//眨眼
  15. const QString AT_SHAKE = "SHAKE";//摇头
  16. const QString AT_NOD = "NOD";//点头
  17. const QString AT_FACE_DETECT = "FACE_DETECT";//人脸检测
  18. };
  19. namespace STATUS_TYPE
  20. {
  21. const QString ST_SUCCESS = "SUCCESS";
  22. const QString ST_ACTION_FAILED = "ACTION_FAILED";
  23. const QString ST_NOT_ONESELF = "NOT_ONESELF";
  24. const QString ST_TIME_OUT = "TIME_OUT";
  25. const QString ST_ERROR = "ERROR";
  26. };
  27. enum class FACE_LIVENESS_TYPE
  28. {
  29. flt_entry_exam = 1,//考前活体
  30. flt_inprogress //考中活体
  31. };
  32. struct LivenessVerifyInfo
  33. {
  34. bool bIsVerify;//检测完成
  35. QString sActionType;//动作类型
  36. QString sUrl;
  37. cv::Mat matImage;
  38. float fSimilarity;
  39. int nRealness;
  40. int nFaceCount;
  41. bool bPass;
  42. int nRetryCount;//重试次数
  43. __int64 nStartTime;//开始时间
  44. __int64 nEndTime;//结束时间
  45. int nActionLeftSceonds;//动作剩余时间
  46. QString sErrorMsg;
  47. LivenessVerifyInfo()
  48. {
  49. bIsVerify = false;
  50. sActionType = "";
  51. sUrl = "";
  52. nRetryCount = 0;
  53. fSimilarity = 0;
  54. nRealness = 0;
  55. nStartTime = 0;
  56. nEndTime = 0;
  57. bPass = false;
  58. nFaceCount = 0;
  59. nActionLeftSceonds = 0;
  60. sErrorMsg = "";
  61. }
  62. void reset(int actionLeftSceonds)
  63. {
  64. bIsVerify = false;
  65. sUrl = "";
  66. matImage = cv::Mat();
  67. bPass = false;
  68. nRetryCount = 0;
  69. fSimilarity = 0;
  70. nRealness = 0;
  71. nStartTime = 0;
  72. nEndTime = 0;
  73. bPass = false;
  74. nFaceCount = 0;
  75. sErrorMsg = "";
  76. nActionLeftSceonds = actionLeftSceonds;
  77. }
  78. };
  79. namespace Ui {
  80. class faceLiveness;
  81. }
  82. class faceLiveness : public QWidget, ITRTCVideoRenderCallback
  83. {
  84. Q_OBJECT
  85. signals:
  86. void faceLivenessFaild();
  87. void faceLivenessSucceed();
  88. public:
  89. explicit faceLiveness(FACE_LIVENESS_TYPE livenessType, QWidget *parent = nullptr);
  90. ~faceLiveness();
  91. private slots:
  92. void on_btn_fl_startVerify_clicked();
  93. void onClientExamProcessUploadSign(CClientExamProcessUploadSign processUpload); //文件上传
  94. void onUploadFileToAliyun(CUploadFileToAliyun uploadFileToAliyun);
  95. void onSaveFaceLiveVerifyResult(CBaseResponsePackage res);//保存人脸活体验证结果
  96. void onSaveFaceCompareResult(CBaseResponsePackage res);
  97. void actionTimer();
  98. void countdownTimer();
  99. void on_btn_fl_close_clicked();
  100. private:
  101. void initUI();
  102. void initAcionIcon();
  103. void saveLivenessResult();
  104. void verifyAction(cv::Mat matImage);
  105. void onRenderVideoFrame(const char* userId, TRTCVideoStreamType streamType, TRTCVideoFrame* frame);
  106. bool setBaseImage();
  107. void saveFaceCampareResult();
  108. void showVerifyResultUI();
  109. Ui::faceLiveness *ui;
  110. std::shared_ptr<QTimer> m_pVideoTimer;
  111. // std::shared_ptr<QTimer> m_pinitTimer;
  112. // cv::VideoCapture m_cam;
  113. std::shared_ptr<QTimer> m_pCloseTimer;
  114. void threadProc();
  115. __int64 m_lastFaceTime = 0;
  116. __int64 m_nStartTime = 0;
  117. __int64 m_nEndTime = 0;
  118. int m_nMaxSeconds = 0;
  119. std::shared_ptr<QTimer> m_ActionTimer;
  120. std::shared_ptr<QTimer> m_countdownTimer;
  121. std::shared_ptr<QTimer> m_initTimer;
  122. std::mutex m_imgMutex;
  123. std::list<cv::Mat> m_imgList;
  124. cv::Mat m_nCurImage;
  125. std::mutex m_imageMutex;
  126. QList<LivenessVerifyInfo> m_livenessList;
  127. int m_nCurIndex;
  128. std::mutex m_livenessListMutex;
  129. LivenessVerifyInfo m_currentVerifyInfo;
  130. float m_fMinYaw;
  131. float m_fMaxYaw;
  132. QString m_sLivenessStatus;
  133. std::thread m_thread;
  134. bool m_bIsRun;
  135. bool m_bStartCompare = false;
  136. int m_nRetryCount = 0;
  137. FACE_LIVENESS_TYPE m_livenessType;
  138. int m_nFaceDetectDuration = 60;
  139. int m_nFaceRetryCount = 0;
  140. int m_nFaceWholeRetryCount = 0;
  141. const int m_nMaxFaceRetryCount = 3;
  142. const int m_nMaxFaceWholeRetryCount = 3;
  143. };
  144. #endif // FACELIVENESS_H