Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MainWindow::process()
- {
- while (_running) {
- QDateTime timestamp = QDateTime::currentDateTime();
- try {
- if (!_frame.cols || !_frame.rows) throw e_failure ("MainWindow: Empty frame");
- _temp = _frame.clone();
- _detector->processDownScale(_temp, 2);
- _mutex.lock();
- _mask.clear();
- _mutex.unlock();
- if (_detector->facesFound()) {
- _mask.push_back(QPointF(_detector->rect().x,
- _detector->rect().y));
- _mask.push_back(QPointF(_detector->rect().x+_detector->rect().width,
- _detector->rect().y+_detector->rect().height));
- _mask.push_back(QPointF(_detector->landmarks()[0].x+_detector->rect().x,
- _detector->landmarks()[0].y+_detector->rect().y));
- _mask.push_back(QPointF(_detector->landmarks()[1].x+_detector->rect().x,
- _detector->landmarks()[1].y+_detector->rect().y));
- _mask.push_back(QPointF(_detector->landmarks()[4].x+_detector->rect().x,
- _detector->landmarks()[4].y+_detector->rect().y));
- _mask.push_back(QPointF(_detector->landmarks()[3].x+_detector->rect().x,
- _detector->landmarks()[3].y+_detector->rect().y));
- _mask.push_back(QPointF(_detector->landmarks()[2].x+_detector->rect().x,
- _detector->landmarks()[2].y+_detector->rect().y));
- }
- switch (_appState) {
- case AppState::Testing:
- if (!_detector->facesFound()) {
- setState(FaceState::Noface);
- throw e_runtime ("MainWindow: No face detected");
- }
- _aligned = _extractor->alignMtcnn(_temp, *_detector);
- if (!_verified) {
- _pattern = _extractor->extract(_aligned);
- _etalon->verifySample(_pattern, &_similarity);
- _verified = _similarity >= 100;
- }
- else if (!_moved) {
- cv::Rect actual = _extractor->usedFaceRect();
- if (_faceRect.area() != 0) {
- cv::Rect is = actual & _faceRect;
- float isf = (float)is.area() / (float)actual.area();
- qDebug() << "intersection" << isf;
- if (isf < 0.75f)
- _headDetector->reset();
- }
- float qual = _extractor->quality();
- qDebug() << "quality" << qual;
- if (qual >= _qualThreshold) {
- if (_progress != 100)
- setState(FaceState::Spoofing);
- _moved = _headDetector->addFrame(_extractor->alignedCenter(), _extractor->alignedNose());
- }
- else {
- if (_progress != 100)
- setState(FaceState::LowQuality);
- _moved = _headDetector->addEmptyFrame();
- }
- }
- if (_verified) {
- if (_moved) {
- _progress = 100;
- _verifyTimer.stop();
- setState(AppState::Ready);
- setState(FaceState::Accepted);
- _verificationTime = _timestamp.msecsTo(QDateTime::currentDateTime());
- }
- }
- _faceRect = _extractor->usedFaceRect();
- break;
- case AppState::Training:
- if (!_detector->facesFound()) {
- setState(FaceState::Noface);
- throw e_failure ("MainWindow: No face detected");
- }
- setState(FaceState::None);
- _pattern = _extractor->extractMtcnnAlign(_temp, *_detector);
- if (_etalon->addSample(_pattern)) {
- _progress += 100/_trainFrames;
- }
- if (_progress >= 100) {
- saveEtalon();
- }
- break;
- default:;
- }
- } catch (e_default e) {
- qDebug() << e.what();
- _similarity = 0;
- } catch (...) {
- _similarity = 0;
- }
- _frameTime = timestamp.msecsTo(QDateTime::currentDateTime());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement