Newer
Older
CasicIrisIdentify / IdentifyForm.cpp
#ifdef _MSC_VER
#pragma execution_character_set("utf-8")    // Qt VS 中文兼容(UTF-8)
#endif

#include "IdentifyForm.h"
#include "ui_IdentifyForm.h"

IdentifyForm::IdentifyForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::IdentifyForm)
{
    ui->setupUi(this);

    ui->wgtIdentifying->setCurrentIndex(0);

    ui->labelIdenTips->setText("");
    ui->labelFailTips->setText("识 别 失 败\n请 重 试");
}

IdentifyForm::~IdentifyForm()
{
    delete ui;
}

void IdentifyForm::updateIdentifyTips(QString tips)
{
    ui->labelIdenTips->setText(tips);
}

void IdentifyForm::drawIrisImageOnFrame(QImage image)
{
    // 只在识别界面才显示画面
    if (ui->wgtIdentifying->currentIndex() == 0) {
        ui->labelVideo->setPixmap(QPixmap::fromImage(image));
    }
}

void IdentifyForm::showRecogFailure()
{
    SpeakerUtil::getInstance().speak("识别失败,请重试");

    ui->wgtIdentifying->setCurrentIndex(2);

    ProMemory::getInstance().clearIrisQueue();
    ProMemory::getInstance().irisRecogPro->setWorking(false);
    ProMemory::getInstance().irisCam->stopCapture();

    QTimer::singleShot(SettingConfig::getInstance().FAILURE_TIPS_LAST, [=](){
        ProMemory::getInstance().irisCam->startCapture();
        ProMemory::getInstance().irisRecogPro->setWorking(true);
        ProMemory::getInstance().appState = AppConstants::ApplicationState::STATE_WORKING;
        ui->labelIdenTips->setText("");

        // 清除上一次识别的状态信息
        CasicIrisRecState::getInstance().restRecognize();
        ui->wgtIdentifying->setCurrentIndex(0);
    });
}

void IdentifyForm::showRecognizeResult(QString personId)
{
    QVariantMap matched = personDao.findRecordById(personId);

    QString deptName = matched.value("deptname").toString();
    QString personName = matched.value("name").toString();
    SpeakerUtil::getInstance().speak(QString("识别成功,%1%2").arg(deptName).arg(personName));

    ui->wgtIdentifying->setCurrentIndex(1);

    // 查询并显示人员信息
    ui->labelName->setText("");
    ui->labelName->setText(personName);
    ui->labelGender->setText("");
    ui->labelGender->setText(CacheManager::getInstance().getGenderName().value(matched.value("gender").toString()).toString());
    ui->labelDept->setText("");
    ui->labelDept->setText(deptName);
    ui->labelTs->setText("");
    ui->labelTs->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm"));

    // 查询并显示头像
    QPixmap photo;
    QString photoPath = QString("images/%1").arg(matched.value("avatar").toString());
    bool succ = photo.load(photoPath);
    if (succ == false) {
        photo.load(":/images/photo.png");
    }

    // 缩放到合适的尺寸
    float rp = photo.width() * 1.0 / photo.height() * 1.0; // 图片的比例
    float rl = ui->labelPhoto->width() * 1.0 / ui->labelPhoto->height() * 1.0; // 显示框的比例

    if (rp <= rl) {
        // 如果图片的比例小则缩放到显示框的高度
        photo = photo.scaledToHeight(ui->labelPhoto->height());
    } else {
        // 如果图片的比例大则缩放到显示框的宽度
        photo = photo.scaledToWidth(ui->labelPhoto->width());
    }
    // 显示
    ui->labelPhoto->setPixmap(photo);

    // 执行数据库操作
    QVariantMap record;
    record.insert("person_id", personId);
    record.insert("date_time", QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"));
    record.insert("rec_type", AppConstants::IdentifyType::IRIS); // 虹膜识别;
    record.insert("dev_code", SettingConfig::getInstance().DEVICE_CODE);
    record.insert("debug_info", CasicIrisRecState::getInstance().toString());
    recordDao.save(record);

    // 返回工作状态和界面
    QTimer::singleShot(SettingConfig::getInstance().SUCCESS_TIPS_LAST, [=](){
        ProMemory::getInstance().irisCam->startCapture();
        ProMemory::getInstance().irisRecogPro->setWorking(true);
        ProMemory::getInstance().appState = AppConstants::ApplicationState::STATE_WORKING;
        ui->labelIdenTips->setText("");

        // 清除上一次识别的状态信息
        CasicIrisRecState::getInstance().restRecognize();
        ui->wgtIdentifying->setCurrentIndex(0);
    });
}