Qt writes video surveillance screen segmentation interface (open source)

In fact, there are still quite a few qt applications in the field of security, especially video surveillance systems, but there is hardly any demo of the most basic video surveillance screen segmentation made by qt on the Internet. Today, it took a few minutes to extract them and release them as open source. Welcome everyone to like it! Source code download: Click to open the link

Run the screenshot:

#ifndef FRMMAIN_H
#define FRMMAIN_H

#include <QtGui>
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
#include <QtWidgets>
#endif

namespace Ui
{
class frmMain;
}

class frmMain : public QWidget
{
    Q_OBJECT

public:
    explicit frmMain(QWidget *parent = 0);
    ~frmMain();

protected:
    bool eventFilter(QObject *watched, QEvent *event);

private:
    Ui :: frmMain * ui;

    bool videoMax;
    int videoCount;
    QString videoType;
    QMenu * videoMenu;
    QList<QLabel *> widgets;

private slots:
    void initForm();
    void initMenu();

private slots:
    void play_video_all();
    void snapshot_video_one();
    void snapshot_video_all();

    void show_video_all();
    void show_video_4();
    void show_video_6();
    void show_video_8();
    void show_video_9();
    void show_video_16();

    void hide_video_all();
    void change_video(int index, int flag);
    void change_video_4(int index);
    void change_video_6(int index);
    void change_video_8(int index);
    void change_video_9(int index);
    void change_video_16(int index);
};

#endif // FRMMAIN_H

  

#include "frmmain.h"
#include "ui_frmmain.h"

#pragma execution_character_set("utf-8")

frmMain::frmMain(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::frmMain)
{
    ui-> setupUi (this);
    this->initForm();
    this->initMenu();
    this->show_video_all();
    QTimer::singleShot(1000, this, SLOT(play_video_all()));
}

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

bool frmMain::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::MouseButtonDblClick) {
        QLabel *widget = (QLabel *) watched;
        if (!videoMax) {
            videoMax = true;
            hide_video_all();
            ui->gridLayout->addWidget(widget, 0, 0);
            widget->setVisible(true);
        } else {
            videoMax = false;
            show_video_all();
        }
    } else if (event->type() == QEvent::MouseButtonPress) {
        if (qApp->mouseButtons() == Qt::RightButton) {
            videoMenu->exec(QCursor::pos());
        }
    }

    return QWidget::eventFilter(watched, event);
}

void frmMain::initForm()
{
    //set style sheet
    QStringList qss;
    qss.append("QFrame{border:2px solid #000000;}");
    qss.append("QLabel{font:75 25px;color:#F0F0F0;border:2px solid #AAAAAA;background:#000000;}");
    qss.append("QLabel:focus{border:2px solid #00BB9E;background:#555555;}");
    ui->frame->setStyleSheet(qss.join(""));

    videoMax = false;
    videoCount = 16;
    videoType = "1_16";

    for (int i = 0; i < videoCount; i++) {
        QLabel *widget = new QLabel;
        widget->setObjectName(QString("video%1").arg(i + 1));
        widget->installEventFilter(this);
        widget->setFocusPolicy(Qt::StrongFocus);
        widget->setAlignment(Qt::AlignCenter);

        //Choose one of the two, you can choose to display the text, or you can choose to display the background image
        //widget->setText(QString("通道 %1").arg(i + 1));
        widget->setPixmap(QPixmap(":/bg_novideo.png"));
        widgets.append(widget);
    }
}

void frmMain::initMenu()
{
    videoMenu = new QMenu(this);
    videoMenu->addAction("Snapshot the current video", this, SLOT(snapshot_video_one()));
    videoMenu->addAction("Snapshot all videos", this, SLOT(snapshot_video_all()));
    videoMenu->addSeparator();

    QMenu *menu4 = videoMenu->addMenu("Switch to 4 pictures");
    menu4->addAction("Channel 1-Channel 4", this, SLOT(show_video_4()));
    menu4->addAction("Channel 5-Channel 8", this, SLOT(show_video_4()));
    menu4->addAction("Channel 9-Channel 12", this, SLOT(show_video_4()));
    menu4->addAction("Channel 13-Channel 16", this, SLOT(show_video_4()));

    QMenu *menu6 = videoMenu->addMenu("Switch to 6 pictures");
    menu6->addAction("Channel 1-Channel 6", this, SLOT(show_video_6()));
    menu6->addAction("Channel 6-Channel 11", this, SLOT(show_video_6()));
    menu6->addAction("Channel 11-Channel 16", this, SLOT(show_video_6()));

    QMenu *menu8 = videoMenu->addMenu("Switch to 8 pictures");
    menu8->addAction("Channel 1-Channel 8", this, SLOT(show_video_8()));
    menu8->addAction("Channel 9-Channel 16", this, SLOT(show_video_8()));

    QMenu *menu9 = videoMenu->addMenu("Switch to 9 pictures");
    menu9->addAction("Channel 1-Channel 9", this, SLOT(show_video_9()));
    menu9->addAction("Channel 8-Channel 16", this, SLOT(show_video_9()));

    videoMenu->addAction("Switch to 16 pictures", this, SLOT(show_video_16()));
}

void frmMain::play_video_all()
{

}

void frmMain::snapshot_video_one()
{

}

void frmMain::snapshot_video_all()
{

}

void frmMain::show_video_all()
{
    if (videoType == "1_4") {
        change_video_4(0);
    } else if (videoType == "5_8") {
        change_video_4(4);
    } else if (videoType == "9_12") {
        change_video_4(8);
    } else if (videoType == "13_16") {
        change_video_4(12);
    } else if (videoType == "1_6") {
        change_video_6(0);
    } else if (videoType == "6_11") {
        change_video_6(5);
    } else if (videoType == "11_16") {
        change_video_6(10);
    } else if (videoType == "1_8") {
        change_video_8(0);
    } else if (videoType == "9_16") {
        change_video_8(8);
    } else if (videoType == "1_9") {
        change_video_9(0);
    } else if (videoType == "8_16") {
        change_video_9(7);
    } else if (videoType == "1_16") {
        change_video_16(0);
    }
}

void frmMain::show_video_4()
{
    videoMax = false;
    QString videoType;
    int index = 0;

    QAction *action = (QAction *)sender();
    QString name = action->text();

    if (name == "Channel 1-Channel 4") {
        index = 0;
        videoType = "1_4";
    } else if (name == "Channel 5-Channel 8") {
        index = 4;
        videoType = "5_8";
    } else if (name == "Channel 9-Channel 12") {
        index = 8;
        videoType = "9_12";
    } else if (name == "Channel 13-Channel 16") {
        index = 12;
        videoType = "13_16";
    }

    if (this->videoType != videoType) {
        this->videoType = videoType;
        change_video_4(index);
    }
}

void frmMain::show_video_6()
{
    videoMax = false;
    QString videoType;
    int index = 0;

    QAction *action = (QAction *)sender();
    QString name = action->text();

    if (name == "Channel 1-Channel 6") {
        index = 0;
        videoType = "1_6";
    } else if (name == "Channel 6-Channel 11") {
        index = 5;
        videoType = "6_11";
    } else if (name == "Channel 11-Channel 16") {
        index = 10;
        videoType = "11_16";
    }

    if (this->videoType != videoType) {
        this->videoType = videoType;
        change_video_6(index);
    }
}

void frmMain::show_video_8()
{
    videoMax = false;
    QString videoType;
    int index = 0;

    QAction *action = (QAction *)sender();
    QString name = action->text();

    if (name == "Channel 1-Channel 8") {
        index = 0;
        videoType = "1_8";
    } else if (name == "Channel 9-Channel 16") {
        index = 8;
        videoType = "9_16";
    }

    if (this->videoType != videoType) {
        this->videoType = videoType;
        change_video_8(index);
    }
}

void frmMain::show_video_9()
{
    videoMax = false;
    QString videoType;
    int index = 0;

    QAction *action = (QAction *)sender();
    QString name = action->text();

    if (name == "Channel 1-Channel 9") {
        index = 0;
        videoType = "1_9";
    } else if (name == "Channel 8-Channel 16") {
        index = 7;
        videoType = "8_16";
    }

    if (this->videoType != videoType) {
        this->videoType = videoType;
        change_video_9(index);
    }
}

void frmMain::show_video_16()
{
    videoMax = false;
    QString videoType;
    int index = 0;
    videoType = "1_16";

    if (this->videoType != videoType) {
        this->videoType = videoType;
        change_video_16(index);
    }
}

void frmMain::hide_video_all()
{
    for (int i = 0; i < videoCount; i++) {
        ui->gridLayout->removeWidget(widgets.at(i));
        widgets.at(i)->setVisible(false);
    }
}

void frmMain::change_video(int index, int flag)
{
    int count = 0;
    int row = 0;
    int column = 0;

    for (int i = 0; i < videoCount; i++) {
        if (i >= index) {
            ui->gridLayout->addWidget(widgets.at(i), row, column);
            widgets.at(i)->setVisible(true);

            count++;
            column++;
            if (column == flag) {
                row++;
                column = 0;
            }
        }

        if (count == (flag * flag)) {
            break;
        }
    }
}

void frmMain::change_video_4(int index)
{
    hide_video_all();
    change_video(index, 2);
}

void frmMain::change_video_6(int index)
{
    hide_video_all();
    if (index == 0) {
        ui->gridLayout->addWidget(widgets.at(0), 0, 0, 2, 2);
        ui->gridLayout->addWidget(widgets.at(1), 0, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(2), 1, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(3), 2, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(4), 2, 1, 1, 1);
        ui->gridLayout->addWidget(widgets.at(5), 2, 0, 1, 1);

        for (int i = 0; i < 6; i++) {
            widgets.at(i)->setVisible(true);
        }
    } else if (index == 5) {
        ui->gridLayout->addWidget(widgets.at(5), 0, 0, 2, 2);
        ui->gridLayout->addWidget(widgets.at(6), 0, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(7), 1, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(8), 2, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(9), 2, 1, 1, 1);
        ui->gridLayout->addWidget(widgets.at(10), 2, 0, 1, 1);

        for (int i = 5; i < 11; i++) {
            widgets.at(i)->setVisible(true);
        }
    } else if (index == 10) {
        ui->gridLayout->addWidget(widgets.at(10), 0, 0, 2, 2);
        ui->gridLayout->addWidget(widgets.at(11), 0, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(12), 1, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(13), 2, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(14), 2, 1, 1, 1);
        ui->gridLayout->addWidget(widgets.at(15), 2, 0, 1, 1);

        for (int i = 10; i < 16; i++) {
            widgets.at(i)->setVisible(true);
        }
    }
}

void frmMain::change_video_8(int index)
{
    hide_video_all();
    if (index == 0) {
        ui->gridLayout->addWidget(widgets.at(0), 0, 0, 3, 3);
        ui->gridLayout->addWidget(widgets.at(1), 0, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(2), 1, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(3), 2, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(4), 3, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(5), 3, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(6), 3, 1, 1, 1);
        ui->gridLayout->addWidget(widgets.at(7), 3, 0, 1, 1);

        for (int i = 0; i < 8; i++) {
            widgets.at(i)->setVisible(true);
        }
    } else if (index == 8) {
        ui->gridLayout->addWidget(widgets.at(8), 0, 0, 3, 3);
        ui->gridLayout->addWidget(widgets.at(9), 0, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(10), 1, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(11), 2, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(12), 3, 3, 1, 1);
        ui->gridLayout->addWidget(widgets.at(13), 3, 2, 1, 1);
        ui->gridLayout->addWidget(widgets.at(14), 3, 1, 1, 1);
        ui->gridLayout->addWidget(widgets.at(15), 3, 0, 1, 1);

        for (int i = 8; i < 16; i++) {
            widgets.at(i)->setVisible(true);
        }
    }
}

void frmMain::change_video_9(int index)
{
    hide_video_all();
    change_video(index, 3);
}

void frmMain::change_video_16(int index)
{
    hide_video_all();
    change_video(index, 4);
}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325397495&siteId=291194637