#include "mainwidget.h" #include #include #include #include #include #include #include #include #include #include #include "faceLib/common.h" #include "opencv2/opencv.hpp" void initDbPersons(int chan); mainWidget::mainWidget(QWidget *parent) : QWidget(parent) , ft(0,1) , fe(1) { qRegisterMetaType("ImgToShow");//注册ImgToShow类型 qRegisterMetaType("std::string");//注册ImgToShow类型 initDbPersons(0); ft.setnSampleSize(640); printf("do Threads... \n"); fe.run(0); ft.run(0); initParams(); initTimer(); QObject::connect(&ft,SIGNAL(drawImage(ImgToShow)),this,SLOT(on_ImageShow(ImgToShow))); QObject::connect(&ft,SIGNAL(signalAdvertise(bool)),this,SLOT(slotAdvertise(bool))); QObject::connect(&ft,SIGNAL(signalTips(std::string)),this,SLOT(slotTips(std::string))); QObject::connect(&fe,SIGNAL(signalTips(std::string)),this,SLOT(slotTips(std::string))); } mainWidget::~mainWidget() { delete pTimer; delete pDateTime; delete pLabelVideo; //video delete pLabelAdv; delete pPixAdv; //advertise pic delete pStackWgt; } void mainWidget::initParams() { QList list_screen = QGuiApplication::screens(); //多显示器 QRect rect = list_screen.at(0)->geometry(); qDebug() << rect.width() << rect.height(); // this->resize(rect.width(), rect.height()); this->resize(800, 600); this->setObjectName("mainWidget"); this->setStyleSheet("QWidget#mainWidget{" "border-image: url(:/res/background.png);}"); pPixAdv = new QPixmap(":/res/adv.jpg"); QVBoxLayout *vLayout = new QVBoxLayout(this); pLabelVideo = new myLabel; pLabelAdv = new QLabel; pStackWgt = new QStackedWidget(this); pStackWgt->addWidget(pLabelVideo); pStackWgt->addWidget(pLabelAdv); vLayout->addWidget(pStackWgt); vLayout->setMargin(10); vLayout->setStretchFactor(pStackWgt,10); this->setLayout(vLayout); this->show();//FullScreen(); } void mainWidget::initTimer() { pTimer = new QTimer; pTimer->setSingleShot(true); connect(pTimer,SIGNAL(timeout()),this,SLOT(slotClear())); } void mainWidget::paintEvent(QPaintEvent *) { QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } void mainWidget::moveEvent(QMoveEvent *) { this->move(QPoint(0,0)); } void mainWidget::slotClear() { pLabelVideo->setMyText(QString("")); pLabelVideo->setMyShow(false); } void mainWidget::slotAdvertise(bool value) { qDebug()<< "void MainWidget::slotAdvertise()" << value; if (value) { std::cout << "111cpStackWgt: " << pStackWgt->width() << "x" << pStackWgt->height() << std::endl; QSize picSize(pStackWgt->width(),pStackWgt->height()); QPixmap scaledPixmap = pPixAdv->scaled(picSize); pLabelAdv->setPixmap(scaledPixmap); pStackWgt->setCurrentIndex(1); } else { pStackWgt->setCurrentIndex(0); } } void initDbPersons(int chan) { std::string basePath = "/data/disk2/face/pic/"; std::vector persons = { "chenshijun", "chenshijun2", "liuxin", "shiyajun", "suntianyu", "wangzong", "zhangzengfei" }; cv::Mat frame; for (auto person:persons) { THFT_FaceInfo faceInfo; frame = cv::imread(basePath + person + ".jpg", cv::IMREAD_COLOR); int ret = THFT_FaceDetect(chan, frame.data, frame.cols, frame.rows, &faceInfo, 1, 0); if (ret > 0) { THFI_FacePos facePos; BYTE *feature = new BYTE[2560]; memcpy(&facePos, &faceInfo, sizeof(THFI_FacePos)); ret = EF_Extract((short) chan, frame.data, frame.cols, frame.rows, 3, &facePos, feature); if (ret == 1) { mFaceRec.insert(std::pair(person, feature)); printf("insert face :%s %p\n", person.c_str(), feature); } } } } void mainWidget::on_ImageShow(ImgToShow image) { if((image.nWidth > 0) && (image.nHeight > 0) && (image.imgData != nullptr)){ QImage qimg((const unsigned char*)image.imgData, image.nWidth, image.nHeight, image.nWidth * 3, QImage::Format_RGB888); auto qpixmap = QPixmap::fromImage(qimg); QSize picSize(pStackWgt->width(),pStackWgt->height()); QPixmap scaledPixmap = qpixmap.scaled(picSize); pLabelVideo->setMyPixmap(scaledPixmap); update(); delete image.imgData; } } void mainWidget::slotTips(std::string str) { pLabelVideo->setMyText(QString(str.data())); pLabelVideo->setMyShow(true); pTimer->start(2000); }