Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. void MainWindow::process()
  2. {
  3. while (_running) {
  4. QDateTime timestamp = QDateTime::currentDateTime();
  5. try {
  6. if (!_frame.cols || !_frame.rows) throw e_failure ("MainWindow: Empty frame");
  7. _temp = _frame.clone();
  8. _detector->processDownScale(_temp, 2);
  9. _mutex.lock();
  10. _mask.clear();
  11. _mutex.unlock();
  12. if (_detector->facesFound()) {
  13. _mask.push_back(QPointF(_detector->rect().x,
  14. _detector->rect().y));
  15. _mask.push_back(QPointF(_detector->rect().x+_detector->rect().width,
  16. _detector->rect().y+_detector->rect().height));
  17. _mask.push_back(QPointF(_detector->landmarks()[0].x+_detector->rect().x,
  18. _detector->landmarks()[0].y+_detector->rect().y));
  19. _mask.push_back(QPointF(_detector->landmarks()[1].x+_detector->rect().x,
  20. _detector->landmarks()[1].y+_detector->rect().y));
  21. _mask.push_back(QPointF(_detector->landmarks()[4].x+_detector->rect().x,
  22. _detector->landmarks()[4].y+_detector->rect().y));
  23. _mask.push_back(QPointF(_detector->landmarks()[3].x+_detector->rect().x,
  24. _detector->landmarks()[3].y+_detector->rect().y));
  25. _mask.push_back(QPointF(_detector->landmarks()[2].x+_detector->rect().x,
  26. _detector->landmarks()[2].y+_detector->rect().y));
  27. }
  28. switch (_appState) {
  29. case AppState::Testing:
  30. if (!_detector->facesFound()) {
  31. setState(FaceState::Noface);
  32. throw e_runtime ("MainWindow: No face detected");
  33. }
  34. _aligned = _extractor->alignMtcnn(_temp, *_detector);
  35. if (!_verified) {
  36. _pattern = _extractor->extract(_aligned);
  37. _etalon->verifySample(_pattern, &_similarity);
  38. _verified = _similarity >= 100;
  39. }
  40. else if (!_moved) {
  41. cv::Rect actual = _extractor->usedFaceRect();
  42. if (_faceRect.area() != 0) {
  43. cv::Rect is = actual & _faceRect;
  44. float isf = (float)is.area() / (float)actual.area();
  45. qDebug() << "intersection" << isf;
  46. if (isf < 0.75f)
  47. _headDetector->reset();
  48. }
  49. float qual = _extractor->quality();
  50. qDebug() << "quality" << qual;
  51. if (qual >= _qualThreshold) {
  52. if (_progress != 100)
  53. setState(FaceState::Spoofing);
  54. _moved = _headDetector->addFrame(_extractor->alignedCenter(), _extractor->alignedNose());
  55. }
  56. else {
  57. if (_progress != 100)
  58. setState(FaceState::LowQuality);
  59. _moved = _headDetector->addEmptyFrame();
  60. }
  61. }
  62. if (_verified) {
  63. if (_moved) {
  64. _progress = 100;
  65. _verifyTimer.stop();
  66. setState(AppState::Ready);
  67. setState(FaceState::Accepted);
  68. _verificationTime = _timestamp.msecsTo(QDateTime::currentDateTime());
  69. }
  70. }
  71. _faceRect = _extractor->usedFaceRect();
  72. break;
  73. case AppState::Training:
  74. if (!_detector->facesFound()) {
  75. setState(FaceState::Noface);
  76. throw e_failure ("MainWindow: No face detected");
  77. }
  78. setState(FaceState::None);
  79. _pattern = _extractor->extractMtcnnAlign(_temp, *_detector);
  80. if (_etalon->addSample(_pattern)) {
  81. _progress += 100/_trainFrames;
  82. }
  83. if (_progress >= 100) {
  84. saveEtalon();
  85. }
  86. break;
  87. default:;
  88. }
  89. } catch (e_default e) {
  90. qDebug() << e.what();
  91. _similarity = 0;
  92. } catch (...) {
  93. _similarity = 0;
  94. }
  95. _frameTime = timestamp.msecsTo(QDateTime::currentDateTime());
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement