QT-RTSP相机监控视频流

news/2024/10/18 3:27:38/

QT-RTSP相机监控视频流

  • 一、演示效果
  • 二、关键程序
  • 三、下载链接

一、演示效果

在这里插入图片描述

二、关键程序

#include "mainwindow.h"#include <QDebug>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_settings("outSmart", "LiveWatcher") {ip_address_edit = new QLineEdit;login_edit = new QLineEdit;password_edit = new QLineEdit;password_edit->setEchoMode(QLineEdit::Password);label0 = new QLabel;label0->setText("IP address:");label1 = new QLabel;label1->setText("Login:");label2 = new QLabel;label2->setText("Password:");button1 = new QPushButton;button1->setText("Connect");connect(button1, SIGNAL(clicked()), SLOT(slotConnectDisconnect()) );videoWidget = new VideoWidget(this);videoWidget->setMinimumSize(704, 576);player0 = new QMediaPlayer;player0->setVideoOutput(videoWidget);layout1 = new QVBoxLayout;layout1->addWidget(label0);layout1->addWidget(ip_address_edit);layout1->addWidget(label1);layout1->addWidget(login_edit);layout1->addWidget(label2);layout1->addWidget(password_edit);spacer0 = new QSpacerItem(30, 40, QSizePolicy::Minimum, QSizePolicy::Maximum);layout1->addSpacerItem(spacer0);layout1->addWidget(button1);layout1->setContentsMargins(10, 10, 10, 10);layout2 = new QVBoxLayout;layout2->addWidget(videoWidget);layout0 = new QHBoxLayout;layout0->addLayout(layout2);layout0->addLayout(layout1);layout0->setAlignment(layout1, Qt::AlignTop) ;QWidget * window = new QWidget();window->setLayout(layout0);setCentralWidget(window);QRegExpValidator *ipValidator = new QRegExpValidator(ipRegex, this);ip_address_edit->setValidator(ipValidator);readSettings();QAction* pactShowHide = new QAction("&Show/Hide Application Window", this);connect(pactShowHide, SIGNAL(triggered()),this,         SLOT(slotShowHide()));QAction* pactQuit = new QAction("&Quit", this);connect(pactQuit, SIGNAL(triggered()), qApp, SLOT(quit()));m_ptrayIconMenu = new QMenu(this);m_ptrayIconMenu->addAction(pactShowHide);m_ptrayIconMenu->addAction(pactQuit);m_ptrayIcon = new QSystemTrayIcon(this);m_ptrayIcon->setContextMenu(m_ptrayIconMenu);m_ptrayIcon->setToolTip("LiveWatcher");m_ptrayIcon->setIcon(QPixmap(":/images/logo.png"));m_ptrayIcon->show();createMenus();}MainWindow::~MainWindow()
{writeSettings();
}void MainWindow::slotConnectDisconnect()
{if (!is_connected) {QString login = login_edit->text() ;QString password = password_edit->text() ;QString ip_address = ip_address_edit->text() ;if (!ipRegex1.match(ip_address).hasMatch() ) {QMessageBox::critical(this, "Error", "Wrong format for IP address");return;}url0 = QUrl("rtsp://" + ip_address + ":554/ISAPI/Streaming/Channels/102");url0.setUserName(login);url0.setPassword(password);requestRtsp0 = QNetworkRequest(url0);player0->setMedia(requestRtsp0);player0->play();is_connected = true;button1->setText("Disconnect");}else {player0->stop();button1->setText("Connect");is_connected = false;}}void MainWindow::keyPressEvent(QKeyEvent *event)
{if (event->key() == Qt::Key_F11) {if (videoWidget != nullptr) {videoWidget->setFullScreen(true);}}else if (event->key() == Qt::Key_Escape) {qApp->quit();}}void MainWindow::writeSettings() {m_settings.beginGroup("/Settings");m_settings.setValue("/ip_address", ip_address_edit->text() ) ;m_settings.setValue("/login", login_edit->text() );m_settings.setValue("/password", password_edit->text() );m_settings.endGroup();}void MainWindow::readSettings() {m_settings.beginGroup("/Settings");ip_address_edit->setText(m_settings.value("/ip_address", "").toString() );login_edit->setText(m_settings.value("/login", "admin").toString() );password_edit->setText(m_settings.value("/password", "Freedom!00##").toString() );m_settings.endGroup();}void MainWindow::slotShowHide()
{setVisible(!isVisible());
}void MainWindow::closeEvent(QCloseEvent * event)
{setVisible(false);event->ignore();
}void MainWindow::showAbout() {QMessageBox::about(this, "About", "aleks.twin@gmail.com");}void MainWindow::createMenus()
{QAction *quit = new QAction("&Quit", this);QMenu *file;file = menuBar()->addMenu(tr("&File"));file->addAction(quit);connect(quit, &QAction::triggered, qApp, QApplication::quit);QMenu *settingsMenu;settingsMenu = menuBar()->addMenu(tr("&Settings"));QAction * colorSettingsAct = new QAction(tr("&Color settings"), this);colorSettingsAct->setStatusTip(tr("Show color settings"));connect(colorSettingsAct, &QAction::triggered, this, &MainWindow::showColorDialog);settingsMenu->addAction(colorSettingsAct);QMenu *helpMenu;helpMenu = menuBar()->addMenu(tr("&Help"));QAction * hotKeysAct = new QAction(tr("&Hot keys"), this);connect(hotKeysAct, &QAction::triggered, this, &MainWindow::showHotKeys);helpMenu->addAction(hotKeysAct);helpMenu->addSeparator();QAction * aboutAct = new QAction(tr("&About"), this);aboutAct->setStatusTip(tr("Create a new file"));connect(aboutAct, &QAction::triggered, this, &MainWindow::showAbout);helpMenu->addAction(aboutAct);}void MainWindow::showColorDialog() {if (!m_colorDialog) {QSlider *brightnessSlider = new QSlider(Qt::Horizontal);brightnessSlider->setRange(-100, 100);brightnessSlider->setValue(videoWidget->brightness());connect(brightnessSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setBrightness);connect(videoWidget, &QVideoWidget::brightnessChanged, brightnessSlider, &QSlider::setValue);QSlider *contrastSlider = new QSlider(Qt::Horizontal);contrastSlider->setRange(-100, 100);contrastSlider->setValue(videoWidget->contrast());connect(contrastSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setContrast);connect(videoWidget, &QVideoWidget::contrastChanged, contrastSlider, &QSlider::setValue);QSlider *hueSlider = new QSlider(Qt::Horizontal);hueSlider->setRange(-100, 100);hueSlider->setValue(videoWidget->hue());connect(hueSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setHue);connect(videoWidget, &QVideoWidget::hueChanged, hueSlider, &QSlider::setValue);QSlider *saturationSlider = new QSlider(Qt::Horizontal);saturationSlider->setRange(-100, 100);saturationSlider->setValue(videoWidget->saturation());connect(saturationSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setSaturation);connect(videoWidget, &QVideoWidget::saturationChanged, saturationSlider, &QSlider::setValue);QFormLayout *layout = new QFormLayout;layout->addRow(tr("Brightness"), brightnessSlider);layout->addRow(tr("Contrast"), contrastSlider);layout->addRow(tr("Hue"), hueSlider);layout->addRow(tr("Saturation"), saturationSlider);QPushButton *button = new QPushButton(tr("Close"));layout->addRow(button);m_colorDialog = new QDialog(this, Qt::WindowSystemMenuHint | Qt::WindowTitleHint);m_colorDialog->setWindowTitle(tr("Color Options"));m_colorDialog->setLayout(layout);connect(button, &QPushButton::clicked, m_colorDialog, &QDialog::close);}m_colorDialog->show();
}void MainWindow::showHotKeys() {QLabel * q_label = new QLabel();q_label->setStyleSheet(styleSheet() );q_label->setText("F11 - full screeen\nEcsape - exit full screen\n");q_label->setContentsMargins(10,10,10,10);q_label->setWindowTitle("Hot keys");q_label->setFixedSize(240, 60);q_label->show();
}

#include "videowidget.h"#include <QKeyEvent>
#include <QMouseEvent>VideoWidget::VideoWidget(QWidget *parent): QVideoWidget(parent)
{setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);QPalette p = palette();p.setColor(QPalette::Window, Qt::black);setPalette(p);setAttribute(Qt::WA_OpaquePaintEvent);
}void VideoWidget::keyPressEvent(QKeyEvent *event)
{if (event->key() == Qt::Key_Escape && isFullScreen()) {setFullScreen(false);event->accept();} else {QVideoWidget::keyPressEvent(event);}
}void VideoWidget::mouseDoubleClickEvent(QMouseEvent *event)
{setFullScreen(!isFullScreen());event->accept();
}void VideoWidget::mousePressEvent(QMouseEvent *event)
{QVideoWidget::mousePressEvent(event);
}

三、下载链接

https://download.csdn.net/download/u013083044/89550321


http://www.ppmy.cn/news/1476862.html

相关文章

Transformer之Attention的通俗理解

什么是 Attention&#xff1f; 在关于Token的文章 中介绍了什么是Token和Token的作用&#xff0c;那么将一堆Token之间的关系和语义进行提取的&#xff0c;就是Attention。其核心就是通过一些升维降维和求积操作&#xff0c;完成对感兴趣的区域进行特征提取。 A t t e n t i o…

前端实现将多个页面导出为pdf(分页)

一、需要用到两个插件&#xff0c;需要安装 vue框架中实现导出pdf npm install --save html2canvas // Dom转canvas再转image npm install jspdf --save // image转pdf二、实现方法 分别获取每个页面的DOM元素&#xff0c;并转为canvas再转image&#xff0c…

【AI资讯】7.19日凌晨OpenAI发布迷你AI模型GPT-4o mini

性价比最高的小模型 北京时间7月19日凌晨&#xff0c;美国OpenAI公司推出一款新的 AI 模型“GPT-4o mini”&#xff0c;即GPT-4o的更小参数量、简化版本。OpenAI表示&#xff0c;GPT-4o mini是目前功能最强大、性价比最高的小参数模型&#xff0c;性能逼近原版GPT-4&#xff0…

Python面试题:使用Python进行元编程:元类和元编程技巧

在 Python 中&#xff0c;元编程是一种编程技巧&#xff0c;它涉及到代码本身的结构和行为的编程。元编程允许你编写能够操作、修改或生成代码的代码。最常见的元编程技术包括使用元类、装饰器和类装饰器。以下是对 Python 元编程的详细讲解&#xff0c;包括元类和一些常用的元…

用python写一个爬虫,爬取google中关于蛇的照片

为了爬取Google中关于蛇的照片&#xff0c;我们可以利用Python中的第三方库进行网页解析和HTTP请求。请注意&#xff0c;这种爬取行为可能违反Google的使用条款&#xff0c;因此建议在合法和允许的情况下使用。以下是一个基本的Python爬虫示例&#xff0c;使用Requests库发送HT…

B树(B-Tree)详解

B树&#xff08;B-Tree&#xff09;详解 B树&#xff08;B-Tree&#xff09;是一种自平衡的树状数据结构&#xff0c;专为磁盘和其他直接访问的辅助存储设备而设计&#xff0c;广泛应用于数据库和文件系统中。B树通过减少磁盘I/O操作的次数&#xff0c;显著提高了数据存取的效…

axios(ajax请求库)

json-server(搭建http服务) json-server用来快速搭建模拟的REST API的工具包 使用json-server 下载&#xff1a;npm install -g json-server创建数据库json文件&#xff1a;db.json开启服务&#xff1a;json-srver --watch db.json axios的基本使用 <!doctype html>…

健康问题查询找搜索引擎还是大模型

随着自然语言处理&#xff08;NLP&#xff09;的最新进展&#xff0c;大型语言模型&#xff08;LLMs&#xff09;已经成为众多信息获取任务中的主要参与者。然而&#xff0c;传统网络搜索引擎&#xff08;SEs&#xff09;在回答用户提交的查询中的作用远未被取代。例如&#xf…