You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Conception/机器狗视频传输.h

42 lines
962 B

1 year ago
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <opencv2/opencv.hpp>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
const std::string stream_url = "http://localhost:8080/?action=stream";
cv::VideoCapture cap(stream_url);
if (!cap.isOpened())
{
qDebug() << "Failed to open MJPEG Streamer video capture";
return;
}
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, [=]()
{
cv::Mat frame;
cap.read(frame);
if (frame.empty())
{
qDebug() << "Failed to capture MJPEG Streamer video frame";
return;
}
QImage qimg((uchar*)frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(qimg));
});
timer->start(33);
}
MainWindow::~MainWindow()
{
delete ui;
}